Skip to content

Commit

Permalink
fix: add Error prefix to Error objects names (#30969)
Browse files Browse the repository at this point in the history
This fixes printing Error objects in Chrome DevTools.

I've observed that Chrome DevTools is not source mapping and linkifying
URLs, when was running this on larger apps. Chrome DevTools talks to V8
via Chrome DevTools protocol, every object has a corresponding
[`RemoteObject`](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject).

When Chrome DevTools sees that Error object is printed in the console,
it will try to prettify it. `description` field of the corresponding
`RemoteObject` for the `Error` JavaScript object is a combination of
`Error` `name`, `message`, `stack` fields. This is not just a raw
`stack` field, so our prefix for this field just doesn't work. [V8 is
actually filtering out first line of the `stack` field, it only keeps
the stack frames as a string, and then this gets prefixed by `name` and
`message` fields, if they are
available](https://source.chromium.org/chromium/chromium/src/+/main:v8/src/inspector/value-mirror.cc;l=252-311;drc=bdc48d1b1312cc40c00282efb1c9c5f41dcdca9a?fbclid=IwZXh0bgNhZW0CMTEAAR1tMm5YC4jqowObad1qXFT98X4RO76CMkCGNSxZ8rVsg6k2RrdvkVFL0i4_aem_e2fRrqotKdkYIeWlJnk0RA).
As an illustration, this:
```
const fakeError = new Error('');
fakeError.name = 'Stack';
fakeError.stack = 'Error Stack:' + stack;
```

will be formatted by `V8` as this `RemoteObject`:
```
{
  ...
  description: 'Stack: ...',
  ...
}
```

Notice that there is no `Error` prefix, that was previously added.
Because of this, [Chrome DevTools won't even try to symbolicate the
stack](https://github.com/ChromeDevTools/devtools-frontend/blob/ee4729d2ccdf5c6715ee40e6697f5464829e3f9a/front_end/panels/console/ErrorStackParser.ts#L33-L35),
because it doesn't have such prefix.

DiffTrain build for [9f4e461](9f4e461)
  • Loading branch information
hoxyq committed Sep 16, 2024
1 parent 0797357 commit a8693be
Show file tree
Hide file tree
Showing 34 changed files with 181 additions and 186 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f2df5694f2be141954f22618fd3ad035203241a3
9f4e4611ead28d34f7f598c9bd12424cf68f5781
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f2df5694f2be141954f22618fd3ad035203241a3
9f4e4611ead28d34f7f598c9bd12424cf68f5781
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-f2df5694-20240916";
exports.version = "19.0.0-www-classic-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-f2df5694-20240916";
exports.version = "19.0.0-www-modern-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-f2df5694-20240916";
exports.version = "19.0.0-www-classic-9f4e4611-20240916";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-f2df5694-20240916";
exports.version = "19.0.0-www-modern-9f4e4611-20240916";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-f2df5694-20240916";
exports.version = "19.0.0-www-classic-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-f2df5694-20240916";
exports.version = "19.0.0-www-modern-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17136,11 +17136,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-classic-f2df5694-20240916",
version: "19.0.0-www-classic-9f4e4611-20240916",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-www-classic-f2df5694-20240916"
reconcilerVersion: "19.0.0-www-classic-9f4e4611-20240916"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -17174,7 +17174,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-classic-f2df5694-20240916";
exports.version = "19.0.0-www-classic-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16582,11 +16582,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-modern-f2df5694-20240916",
version: "19.0.0-www-modern-9f4e4611-20240916",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-www-modern-f2df5694-20240916"
reconcilerVersion: "19.0.0-www-modern-9f4e4611-20240916"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -16620,7 +16620,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-modern-f2df5694-20240916";
exports.version = "19.0.0-www-modern-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10891,13 +10891,13 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1424 = {
bundleType: 0,
version: "19.0.0-www-classic-f2df5694-20240916",
version: "19.0.0-www-classic-9f4e4611-20240916",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function () {
return null;
},
reconcilerVersion: "19.0.0-www-classic-f2df5694-20240916"
reconcilerVersion: "19.0.0-www-classic-9f4e4611-20240916"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1425 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -10923,4 +10923,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-classic-f2df5694-20240916";
exports.version = "19.0.0-www-classic-9f4e4611-20240916";
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10405,13 +10405,13 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1416 = {
bundleType: 0,
version: "19.0.0-www-modern-f2df5694-20240916",
version: "19.0.0-www-modern-9f4e4611-20240916",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function () {
return null;
},
reconcilerVersion: "19.0.0-www-modern-f2df5694-20240916"
reconcilerVersion: "19.0.0-www-modern-9f4e4611-20240916"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1417 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -10437,4 +10437,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-modern-f2df5694-20240916";
exports.version = "19.0.0-www-modern-9f4e4611-20240916";
28 changes: 14 additions & 14 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -18691,41 +18691,41 @@ __DEV__ &&
: !1;
}
function getActiveElementDeep(containerInfo) {
var $jscomp$optchain$tmp1995650823$1, $jscomp$nullish$tmp0;
var $jscomp$optchain$tmpm416247262$1, $jscomp$nullish$tmp0;
containerInfo =
null !=
($jscomp$nullish$tmp0 =
null == containerInfo
? void 0
: null ==
($jscomp$optchain$tmp1995650823$1 = containerInfo.ownerDocument)
($jscomp$optchain$tmpm416247262$1 = containerInfo.ownerDocument)
? void 0
: $jscomp$optchain$tmp1995650823$1.defaultView)
: $jscomp$optchain$tmpm416247262$1.defaultView)
? $jscomp$nullish$tmp0
: window;
for (
$jscomp$optchain$tmp1995650823$1 = getActiveElement(
$jscomp$optchain$tmpm416247262$1 = getActiveElement(
containerInfo.document
);
$jscomp$optchain$tmp1995650823$1 instanceof
$jscomp$optchain$tmpm416247262$1 instanceof
containerInfo.HTMLIFrameElement;

) {
try {
var JSCompiler_inline_result =
"string" ===
typeof $jscomp$optchain$tmp1995650823$1.contentWindow.location.href;
typeof $jscomp$optchain$tmpm416247262$1.contentWindow.location.href;
} catch (err) {
JSCompiler_inline_result = !1;
}
if (JSCompiler_inline_result)
containerInfo = $jscomp$optchain$tmp1995650823$1.contentWindow;
containerInfo = $jscomp$optchain$tmpm416247262$1.contentWindow;
else break;
$jscomp$optchain$tmp1995650823$1 = getActiveElement(
$jscomp$optchain$tmpm416247262$1 = getActiveElement(
containerInfo.document
);
}
return $jscomp$optchain$tmp1995650823$1;
return $jscomp$optchain$tmpm416247262$1;
}
function hasSelectionCapabilities(elem) {
var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
Expand Down Expand Up @@ -27890,11 +27890,11 @@ __DEV__ &&
: flushSyncErrorInBuildsThatSupportLegacyMode;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-www-classic-f2df5694-20240916" !== isomorphicReactPackageVersion)
if ("19.0.0-www-classic-9f4e4611-20240916" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.0.0-www-classic-f2df5694-20240916\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.0.0-www-classic-9f4e4611-20240916\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -27938,11 +27938,11 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-classic-f2df5694-20240916",
version: "19.0.0-www-classic-9f4e4611-20240916",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getClosestInstanceFromNode,
reconcilerVersion: "19.0.0-www-classic-f2df5694-20240916"
reconcilerVersion: "19.0.0-www-classic-9f4e4611-20240916"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -28595,7 +28595,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.0.0-www-classic-f2df5694-20240916";
exports.version = "19.0.0-www-classic-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
28 changes: 14 additions & 14 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -18025,43 +18025,43 @@ __DEV__ &&
: !1;
}
function getActiveElementDeep(containerInfo) {
var $jscomp$optchain$tmpm2116275655$1, $jscomp$nullish$tmp0;
var $jscomp$optchain$tmpm1919935402$1, $jscomp$nullish$tmp0;
containerInfo =
null !=
($jscomp$nullish$tmp0 =
null == containerInfo
? void 0
: null ==
($jscomp$optchain$tmpm2116275655$1 =
($jscomp$optchain$tmpm1919935402$1 =
containerInfo.ownerDocument)
? void 0
: $jscomp$optchain$tmpm2116275655$1.defaultView)
: $jscomp$optchain$tmpm1919935402$1.defaultView)
? $jscomp$nullish$tmp0
: window;
for (
$jscomp$optchain$tmpm2116275655$1 = getActiveElement(
$jscomp$optchain$tmpm1919935402$1 = getActiveElement(
containerInfo.document
);
$jscomp$optchain$tmpm2116275655$1 instanceof
$jscomp$optchain$tmpm1919935402$1 instanceof
containerInfo.HTMLIFrameElement;

) {
try {
var JSCompiler_inline_result =
"string" ===
typeof $jscomp$optchain$tmpm2116275655$1.contentWindow.location
typeof $jscomp$optchain$tmpm1919935402$1.contentWindow.location
.href;
} catch (err) {
JSCompiler_inline_result = !1;
}
if (JSCompiler_inline_result)
containerInfo = $jscomp$optchain$tmpm2116275655$1.contentWindow;
containerInfo = $jscomp$optchain$tmpm1919935402$1.contentWindow;
else break;
$jscomp$optchain$tmpm2116275655$1 = getActiveElement(
$jscomp$optchain$tmpm1919935402$1 = getActiveElement(
containerInfo.document
);
}
return $jscomp$optchain$tmpm2116275655$1;
return $jscomp$optchain$tmpm1919935402$1;
}
function hasSelectionCapabilities(elem) {
var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
Expand Down Expand Up @@ -27009,11 +27009,11 @@ __DEV__ &&
return_targetInst = null;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.0.0-www-modern-f2df5694-20240916" !== isomorphicReactPackageVersion)
if ("19.0.0-www-modern-9f4e4611-20240916" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.0.0-www-modern-f2df5694-20240916\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.0.0-www-modern-9f4e4611-20240916\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -27056,11 +27056,11 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-modern-f2df5694-20240916",
version: "19.0.0-www-modern-9f4e4611-20240916",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getClosestInstanceFromNode,
reconcilerVersion: "19.0.0-www-modern-f2df5694-20240916"
reconcilerVersion: "19.0.0-www-modern-9f4e4611-20240916"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -27665,7 +27665,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.0.0-www-modern-f2df5694-20240916";
exports.version = "19.0.0-www-modern-9f4e4611-20240916";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Loading

0 comments on commit a8693be

Please sign in to comment.