MCPcopy Index your code
hub / github.com/react/react / logCaughtError

Function logCaughtError

packages/react-reconciler/src/ReactFiberErrorLogger.js:163–193  ·  view source on GitHub ↗
(
  root: FiberRoot,
  boundary: Fiber,
  errorInfo: CapturedValue<mixed>,
)

Source from the content-addressed store, hash-verified

161}
162
163export function logCaughtError(
164 root: FiberRoot,
165 boundary: Fiber,
166 errorInfo: CapturedValue<mixed>,
167): void {
168 try {
169 if (__DEV__) {
170 componentName = errorInfo.source
171 ? getComponentNameFromFiber(errorInfo.source)
172 : null;
173 errorBoundaryName = getComponentNameFromFiber(boundary);
174 }
175 const error = (errorInfo.value: any);
176 const onCaughtError = root.onCaughtError;
177 onCaughtError(error, {
178 componentStack: errorInfo.stack,
179 errorBoundary:
180 boundary.tag === ClassComponent
181 ? boundary.stateNode // This should always be the case as long as we only have class boundaries
182 : null,
183 });
184 } catch (e) {
185 // This method must not throw, or React internal state will get messed up.
186 // If console.error is overridden, or logCapturedError() shows a dialog that throws,
187 // we want to report this error outside of the normal stack as a last resort.
188 // https://github.com/facebook/react/issues/13188
189 setTimeout(() => {
190 throw e;
191 });
192 }
193}

Callers 1

Calls 2

onCaughtErrorFunction · 0.85

Tested by

no test coverage detected