MCPcopy Create free account
hub / github.com/brillout/react-streaming / getErrorWithComponentStack

Function getErrorWithComponentStack

src/server/renderToStream/common.ts:93–117  ·  view source on GitHub ↗
(errorOriginal: unknown, errorInfo?: ErrorInfo)

Source from the content-addressed store, hash-verified

91// - Client counterpart: https://github.com/vikejs/vike-react/blob/80fde437bfab666e5b4a0a30386300363bd99939/packages/vike-react/src/integration/onRenderClient.tsx#L108
92type ErrorInfo = { componentStack?: string }
93function getErrorWithComponentStack(errorOriginal: unknown, errorInfo?: ErrorInfo) {
94 if (!errorInfo?.componentStack || !isObject(errorOriginal)) return errorOriginal
95 const errorStackLines = String(errorOriginal.stack).split('\n')
96
97 // Inject the component stack right before the React stack trace (potentially *after* some vike-react or react-streaming strack trace, e.g. if react-streaming's useAsync() throws an error).
98 const cutoff = errorStackLines.findIndex((l) => {
99 l = toPosixPath(l)
100 return l.includes('node_modules/react-dom/') || l.includes('node_modules/react/')
101 })
102 if (cutoff === -1) return errorOriginal
103
104 const errorStackLinesBegin = errorStackLines.slice(0, cutoff)
105 const errorStackLinesEnd = errorStackLines.slice(cutoff)
106 const componentStackLines = errorInfo.componentStack.split('\n').filter(Boolean)
107 if (componentStackLines[0] === errorStackLinesBegin.at(-1)) componentStackLines.shift()
108 const stackEnhanced = [
109 //
110 ...errorStackLinesBegin,
111 ...componentStackLines,
112 ...errorStackLinesEnd,
113 ].join('\n')
114
115 const errorBetter = getBetterError(errorOriginal, { stack: stackEnhanced })
116 return errorBetter
117}

Callers 2

onShellErrorFunction · 0.85
onBoundaryErrorFunction · 0.85

Calls 3

isObjectFunction · 0.85
toPosixPathFunction · 0.85
getBetterErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…