Skip to content

Commit 0fda2b4

Browse files
committed
[Flight] Improve error message when it's not a real Error object (#28327)
Also deals with symbols. Alternative to #28312. We currently always normalize rejections or thrown values into `Error` objects. Partly because in prod it'll be an error object and you shouldn't fork behavior on knowing the value outside a digest. We might want to even make the message always opaque to avoid being tempted and then discover in prod that it doesn't work. However, we do include the message in DEV. If this is a non-Error object we don't know what the properties mean. Ofc, we don't want to include too much information in the rendered string, so we use the general `describeObjectForErrorMessage` helper. Unfortunately it's pretty conservative about emitting values so it's likely to exclude any embedded string atm. Could potentially expand it a bit. We could in theory try to serialize as much as possible and re-throw the actual object to allow for inspection to be expanded inside devtools which is what I plan on for consoles, but since we're normalizing to an Error this is in conflict with that approach. DiffTrain build for [a7144f2](a7144f2)
1 parent 3322b72 commit 0fda2b4

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

compiled/facebook-www/REVISION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
64e755d7374d753c75dc16ba1a4a09ce7b8689dd
1+
a7144f297c1c6fe457ca30ce6a211ab59feac11e

compiled/facebook-www/ReactDOMTesting-prod.modern.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17080,7 +17080,7 @@ Internals.Events = [
1708017080
var devToolsConfig$jscomp$inline_1789 = {
1708117081
findFiberByHostInstance: getClosestInstanceFromNode,
1708217082
bundleType: 0,
17083-
version: "18.3.0-www-modern-589eead3",
17083+
version: "18.3.0-www-modern-f74843f1",
1708417084
rendererPackageName: "react-dom"
1708517085
};
1708617086
var internals$jscomp$inline_2160 = {
@@ -17111,7 +17111,7 @@ var internals$jscomp$inline_2160 = {
1711117111
scheduleRoot: null,
1711217112
setRefreshHandler: null,
1711317113
getCurrentFiber: null,
17114-
reconcilerVersion: "18.3.0-www-modern-589eead3"
17114+
reconcilerVersion: "18.3.0-www-modern-f74843f1"
1711517115
};
1711617116
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1711717117
var hook$jscomp$inline_2161 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17532,4 +17532,4 @@ exports.useFormState = function (action, initialState, permalink) {
1753217532
exports.useFormStatus = function () {
1753317533
return ReactCurrentDispatcher$2.current.useHostTransitionStatus();
1753417534
};
17535-
exports.version = "18.3.0-www-modern-589eead3";
17535+
exports.version = "18.3.0-www-modern-f74843f1";

compiled/facebook-www/ReactFlightDOMServer-dev.modern.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2335,8 +2335,11 @@ if (__DEV__) {
23352335
message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
23362336

23372337
stack = String(error.stack);
2338+
} else if (typeof error === "object" && error !== null) {
2339+
message = "Error: " + describeObjectForErrorMessage(error);
23382340
} else {
2339-
message = "Error: " + error;
2341+
// eslint-disable-next-line react-internal/safe-string-coercion
2342+
message = "Error: " + String(error);
23402343
}
23412344
} catch (x) {
23422345
message =

0 commit comments

Comments
 (0)