Skip to content

Commit

Permalink
[Flight] Improve error message when it's not a real Error object (#28327
Browse files Browse the repository at this point in the history
)

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)
  • Loading branch information
sebmarkbage committed Feb 14, 2024
1 parent 3322b72 commit 0fda2b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
64e755d7374d753c75dc16ba1a4a09ce7b8689dd
a7144f297c1c6fe457ca30ce6a211ab59feac11e
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactDOMTesting-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -17080,7 +17080,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1789 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-modern-589eead3",
version: "18.3.0-www-modern-f74843f1",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2160 = {
Expand Down Expand Up @@ -17111,7 +17111,7 @@ var internals$jscomp$inline_2160 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-589eead3"
reconcilerVersion: "18.3.0-www-modern-f74843f1"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2161 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -17532,4 +17532,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactCurrentDispatcher$2.current.useHostTransitionStatus();
};
exports.version = "18.3.0-www-modern-589eead3";
exports.version = "18.3.0-www-modern-f74843f1";
5 changes: 4 additions & 1 deletion compiled/facebook-www/ReactFlightDOMServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2335,8 +2335,11 @@ if (__DEV__) {
message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion

stack = String(error.stack);
} else if (typeof error === "object" && error !== null) {
message = "Error: " + describeObjectForErrorMessage(error);
} else {
message = "Error: " + error;
// eslint-disable-next-line react-internal/safe-string-coercion
message = "Error: " + String(error);
}
} catch (x) {
message =
Expand Down

0 comments on commit 0fda2b4

Please sign in to comment.