Skip to content

Commit 626cf89

Browse files
committed
[ReactDebugTools] override error name instead of custom error class
1 parent 7068622 commit 626cf89

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/react-debug-tools/src/ReactDebugCustomErrors.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ export const ErrorsNames = {
1818
UNSUPPORTTED_FEATURE_ERROR: 'UnsupportedFeatureError',
1919
};
2020

21-
export function UnsupportedFeatureError(message: string = "") {
22-
// Make this an instanceof Error.
23-
this.constructor.prototype.__proto__ = Error.prototype;
24-
25-
this.name = ErrorsNames.UNSUPPORTTED_FEATURE_ERROR;
26-
this.message = message;
27-
if (Error.captureStackTrace) { // only available in V8
28-
Error.captureStackTrace(this, this.constructor);
29-
}
21+
// For now we just override the name. If we decide to move react-debug-tools to
22+
// devtools package, we should use a real Error class instead.
23+
export function createUnsupportedFeatureError(message: string = "") {
24+
const error = new Error(message);
25+
error.name = ErrorsNames.UNSUPPORTTED_FEATURE_ERROR;
26+
return error;
3027
}

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
ContextProvider,
3030
ForwardRef,
3131
} from 'react-reconciler/src/ReactWorkTags';
32-
import {UnsupportedFeatureError} from './ReactDebugCustomErrors';
32+
import {createUnsupportedFeatureError} from './ReactDebugCustomErrors';
3333

3434
type CurrentDispatcherRef = typeof ReactSharedInternals.ReactCurrentDispatcher;
3535

@@ -364,7 +364,7 @@ const DispatcherProxyHandler = {
364364
if (target.hasOwnProperty(prop)) {
365365
return Reflect.get(...arguments);
366366
}
367-
throw new UnsupportedFeatureError('Missing method in Dispatcher: ' + prop);
367+
throw createUnsupportedFeatureError('Missing method in Dispatcher: ' + prop);
368368
},
369369
};
370370

0 commit comments

Comments
 (0)