MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / setCause

Function setCause

packages/react/src/error.ts:17–34  ·  view source on GitHub ↗
(error: Error & { cause?: Error }, cause: Error)

Source from the content-addressed store, hash-verified

15 * Recurse through `error.cause` chain to set cause on an error.
16 */
17export function setCause(error: Error & { cause?: Error }, cause: Error): void {
18 const seenErrors = new WeakSet();
19
20 function recurse(error: Error & { cause?: Error }, cause: Error): void {
21 // If we've already seen the error, there is a recursive loop somewhere in the error's
22 // cause chain. Let's just bail out then to prevent a stack overflow.
23 if (seenErrors.has(error)) {
24 return;
25 }
26 if (error.cause) {
27 seenErrors.add(error);
28 return recurse(error.cause, cause);
29 }
30 error.cause = cause;
31 }
32
33 recurse(error, cause);
34}
35
36/**
37 * Captures an error that was thrown by a React ErrorBoundary or React root.

Callers 1

captureReactExceptionFunction · 0.85

Calls 1

recurseFunction · 0.85

Tested by

no test coverage detected