Skip to content

Commit

Permalink
Remove Error: prefix
Browse files Browse the repository at this point in the history
These don't really make sense to add to the message string since these prefixes
are typically printed when the errors are printed anyway and are part of .stack.

So prefixing just leads to duplicate prefixes.
  • Loading branch information
sebmarkbage committed Feb 15, 2024
1 parent d875c0c commit aa9f1e7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
22 changes: 10 additions & 12 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,12 @@ describe('ReactFlight', () => {
<Throw value={new TypeError('This is a real Error.')} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: This is a string error.">
<ClientErrorBoundary expectedMessage="This is a string error.">
<div>
<Throw value="This is a string error." />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: {message: ..., extra: ..., nested: ...}">
<ClientErrorBoundary expectedMessage="{message: ..., extra: ..., nested: ...}">
<div>
<Throw
value={{
Expand All @@ -816,9 +816,7 @@ describe('ReactFlight', () => {
</div>
</ClientErrorBoundary>
<ClientErrorBoundary
expectedMessage={
'Error: {message: "Short", extra: ..., nested: ...}'
}>
expectedMessage={'{message: "Short", extra: ..., nested: ...}'}>
<div>
<Throw
value={{
Expand All @@ -829,32 +827,32 @@ describe('ReactFlight', () => {
/>
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: Symbol(hello)">
<ClientErrorBoundary expectedMessage="Symbol(hello)">
<div>
<Throw value={Symbol('hello')} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: 123">
<ClientErrorBoundary expectedMessage="123">
<div>
<Throw value={123} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: undefined">
<ClientErrorBoundary expectedMessage="undefined">
<div>
<Throw value={undefined} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: <div/>">
<ClientErrorBoundary expectedMessage="<div/>">
<div>
<Throw value={<div />} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage="Error: function Foo() {}">
<ClientErrorBoundary expectedMessage="function Foo() {}">
<div>
<Throw value={function Foo() {}} />
</div>
</ClientErrorBoundary>
<ClientErrorBoundary expectedMessage={'Error: ["array"]'}>
<ClientErrorBoundary expectedMessage={'["array"]'}>
<div>
<Throw value={['array']} />
</div>
Expand All @@ -874,7 +872,7 @@ describe('ReactFlight', () => {
} else if (typeof x === 'object' && x !== null) {
return `digest({})`;
}
return `digest(Error: ${String(x)})`;
return `digest(${String(x)})`;
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,7 @@ describe('ReactFlightDOM', () => {
abort('for reasons');
});
if (__DEV__) {
expect(container.innerHTML).toBe(
'<p>Error: for reasons + a dev digest</p>',
);
expect(container.innerHTML).toBe('<p>for reasons + a dev digest</p>');
} else {
expect(container.innerHTML).toBe('<p>digest("for reasons")</p>');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ describe('ReactFlightDOMBrowser', () => {
controller.abort('for reasons');
});
const expectedValue = __DEV__
? '<p>Error: for reasons + a dev digest</p>'
? '<p>for reasons + a dev digest</p>'
: '<p>digest("for reasons")</p>';
expect(container.innerHTML).toBe(expectedValue);

Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,10 @@ function encodeErrorForBoundary(
// eslint-disable-next-line react-internal/safe-string-coercion
message = String(error.message);
} else if (typeof error === 'object' && error !== null) {
message = 'Error: ' + describeObjectForErrorMessage(error);
message = describeObjectForErrorMessage(error);
} else {
// eslint-disable-next-line react-internal/safe-string-coercion
message = 'Error: ' + String(error);
message = String(error);
}

boundary.errorMessage = message;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,10 +1678,10 @@ function emitErrorChunk(
// eslint-disable-next-line react-internal/safe-string-coercion
stack = String(error.stack);
} else if (typeof error === 'object' && error !== null) {
message = 'Error: ' + describeObjectForErrorMessage(error);
message = describeObjectForErrorMessage(error);
} else {
// eslint-disable-next-line react-internal/safe-string-coercion
message = 'Error: ' + String(error);
message = String(error);
}
} catch (x) {
message = 'An error occurred but serializing the error message failed.';
Expand Down

0 comments on commit aa9f1e7

Please sign in to comment.