MCPcopy Create free account
hub / github.com/danielstocks/react-sortable / captureError

Function captureError

bundle.js:7868–7908  ·  view source on GitHub ↗
(failedWork,error)

Source from the content-addressed store, hash-verified

7866isPerformingWork=false;deadlineHasExpired=false;didFatal=false;firstUncaughtError=null;capturedErrors=null;failedBoundaries=null;nextRenderedTree=null;nestedUpdateCount=0;{stopWorkLoopTimer();}// It's safe to throw any unhandled errors.
7867if(errorToThrow!==null){throw errorToThrow;}}// Returns the boundary that captured the error, or null if the error is ignored
7868function captureError(failedWork,error){// It is no longer valid because we exited the user code.
7869ReactCurrentOwner$1.current=null;{ReactDebugCurrentFiber$3.resetCurrentFiber();}// Search for the nearest error boundary.
7870var boundary=null;// Passed to logCapturedError()
7871var errorBoundaryFound=false;var willRetry=false;var errorBoundaryName=null;// Host containers are a special case. If the failed work itself is a host
7872// container, then it acts as its own boundary. In all other cases, we
7873// ignore the work itself and only search through the parents.
7874if(failedWork.tag===HostRoot$6){boundary=failedWork;if(isFailedBoundary(failedWork)){// If this root already failed, there must have been an error when
7875// attempting to unmount it. This is a worst-case scenario and
7876// should only be possible if there's a bug in the renderer.
7877didFatal=true;}}else{var node=failedWork['return'];while(node!==null&&boundary===null){if(node.tag===ClassComponent$5){var instance=node.stateNode;if(typeof instance.componentDidCatch==='function'){errorBoundaryFound=true;errorBoundaryName=getComponentName_1(node);// Found an error boundary!
7878boundary=node;willRetry=true;}}else if(node.tag===HostRoot$6){// Treat the root like a no-op error boundary
7879boundary=node;}if(isFailedBoundary(node)){// This boundary is already in a failed state.
7880// If we're currently unmounting, that means this error was
7881// thrown while unmounting a failed subtree. We should ignore
7882// the error.
7883if(isUnmounting){return null;}// If we're in the commit phase, we should check to see if
7884// this boundary already captured an error during this commit.
7885// This case exists because multiple errors can be thrown during
7886// a single commit without interruption.
7887if(commitPhaseBoundaries!==null&&(commitPhaseBoundaries.has(node)||node.alternate!==null&&commitPhaseBoundaries.has(node.alternate))){// If so, we should ignore this error.
7888return null;}// The error should propagate to the next boundary -— we keep looking.
7889boundary=null;willRetry=false;}node=node['return'];}}if(boundary!==null){// Add to the collection of failed boundaries. This lets us know that
7890// subsequent errors in this subtree should propagate to the next boundary.
7891if(failedBoundaries===null){failedBoundaries=new Set();}failedBoundaries.add(boundary);// This method is unsafe outside of the begin and complete phases.
7892// We might be in the commit phase when an error is captured.
7893// The risk is that the return path from this Fiber may not be accurate.
7894// That risk is acceptable given the benefit of providing users more context.
7895var _componentStack=getStackAddendumByWorkInProgressFiber$2(failedWork);var _componentName=getComponentName_1(failedWork);// Add to the collection of captured errors. This is stored as a global
7896// map of errors and their component stack location keyed by the boundaries
7897// that capture them. We mostly use this Map as a Set; it's a Map only to
7898// avoid adding a field to Fiber to store the error.
7899if(capturedErrors===null){capturedErrors=new Map();}var capturedError={componentName:_componentName,componentStack:_componentStack,error:error,errorBoundary:errorBoundaryFound?boundary.stateNode:null,errorBoundaryFound:errorBoundaryFound,errorBoundaryName:errorBoundaryName,willRetry:willRetry};capturedErrors.set(boundary,capturedError);try{logCapturedError(capturedError);}catch(e){// Prevent cycle if logCapturedError() throws.
7900// A cycle may still occur if logCapturedError renders a component that throws.
7901console.error(e);}// If we're in the commit phase, defer scheduling an update on the
7902// boundary until after the commit is complete
7903if(isCommitting){if(commitPhaseBoundaries===null){commitPhaseBoundaries=new Set();}commitPhaseBoundaries.add(boundary);}else{// Otherwise, schedule an update now.
7904// TODO: Is this actually necessary during the render phase? Is it
7905// possible to unwind and continue rendering at the same priority,
7906// without corrupting internal state?
7907scheduleErrorRecovery(boundary);}return boundary;}else if(firstUncaughtError===null){// If no boundary is found, we'll need to throw the error
7908firstUncaughtError=error;}return null;}function hasCapturedError(fiber){// TODO: capturedErrors should store the boundary instance, to avoid needing
7909// to check the alternate.
7910return capturedErrors!==null&&(capturedErrors.has(fiber)||fiber.alternate!==null&&capturedErrors.has(fiber.alternate));}function isFailedBoundary(fiber){// TODO: failedBoundaries should store the boundary instance, to avoid
7911// needing to check the alternate.

Callers 4

safelyDetachRefFunction · 0.85
commitAllWorkFunction · 0.85
performWorkFunction · 0.85

Calls 2

isFailedBoundaryFunction · 0.85
scheduleErrorRecoveryFunction · 0.85

Tested by

no test coverage detected