MCPcopy
hub / github.com/facebook/react / encodeErrorForBoundary

Function encodeErrorForBoundary

packages/react-server/src/ReactFizzServer.js:1169–1200  ·  view source on GitHub ↗
(
  boundary: SuspenseBoundary,
  digest: ?string,
  error: mixed,
  thrownInfo: ThrownInfo,
  wasAborted: boolean,
)

Source from the content-addressed store, hash-verified

1167}
1168
1169function encodeErrorForBoundary(
1170 boundary: SuspenseBoundary,
1171 digest: ?string,
1172 error: mixed,
1173 thrownInfo: ThrownInfo,
1174 wasAborted: boolean,
1175) {
1176 boundary.errorDigest = digest;
1177 if (__DEV__) {
1178 let message, stack;
1179 // In dev we additionally encode the error message and component stack on the boundary
1180 if (error instanceof Error) {
1181 // eslint-disable-next-line react-internal/safe-string-coercion
1182 message = String(error.message);
1183 // eslint-disable-next-line react-internal/safe-string-coercion
1184 stack = String(error.stack);
1185 } else if (typeof error === 'object' && error !== null) {
1186 message = describeObjectForErrorMessage(error);
1187 stack = null;
1188 } else {
1189 // eslint-disable-next-line react-internal/safe-string-coercion
1190 message = String(error);
1191 stack = null;
1192 }
1193 const prefix = wasAborted
1194 ? 'Switched to client rendering because the server rendering aborted due to:\n\n'
1195 : 'Switched to client rendering because the server rendering errored:\n\n';
1196 boundary.errorMessage = prefix + message;
1197 boundary.errorStack = stack !== null ? prefix + stack : null;
1198 boundary.errorComponentStack = thrownInfo.componentStack;
1199 }
1200}
1201
1202function logPostpone(
1203 request: Request,

Callers 6

renderSuspenseBoundaryFunction · 0.85
replaySuspenseBoundaryFunction · 0.85
erroredTaskFunction · 0.85
abortTaskFunction · 0.85

Calls 1

Tested by

no test coverage detected