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

Function serializeErrorValue

packages/react-server/src/ReactFlightServer.js:4067–4097  ·  view source on GitHub ↗
(request: Request, error: Error)

Source from the content-addressed store, hash-verified

4065}
4066
4067function serializeErrorValue(request: Request, error: Error): string {
4068 if (__DEV__) {
4069 let name: string = 'Error';
4070 let message: string;
4071 let stack: ReactStackTrace;
4072 let env = (0, request.environmentName)();
4073 try {
4074 name = error.name;
4075 // eslint-disable-next-line react-internal/safe-string-coercion
4076 message = String(error.message);
4077 stack = filterStackTrace(request, parseStackTrace(error, 0));
4078 const errorEnv = (error: any).environmentName;
4079 if (typeof errorEnv === 'string') {
4080 // This probably came from another FlightClient as a pass through.
4081 // Keep the environment name.
4082 env = errorEnv;
4083 }
4084 } catch (x) {
4085 message = 'An error occurred but serializing the error message failed.';
4086 stack = [];
4087 }
4088 const errorInfo: ReactErrorInfoDev = {name, message, stack, env};
4089 const id = outlineModel(request, errorInfo);
4090 return '$Z' + id.toString(16);
4091 } else {
4092 // In prod we don't emit any information about this Error object to avoid
4093 // unintentional leaks. Since this doesn't actually throw on the server
4094 // we don't go through onError and so don't register any digest neither.
4095 return '$Z';
4096 }
4097}
4098
4099function serializeDebugErrorValue(request: Request, error: Error): string {
4100 if (__DEV__) {

Callers 1

renderModelDestructiveFunction · 0.85

Calls 4

filterStackTraceFunction · 0.85
outlineModelFunction · 0.85
parseStackTraceFunction · 0.70
toStringMethod · 0.65

Tested by

no test coverage detected