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

Function getException

packages/core/src/utils/eventbuilder.ts:112–147  ·  view source on GitHub ↗
(
  client: Client,
  mechanism: Mechanism,
  exception: unknown,
  hint?: EventHint,
)

Source from the content-addressed store, hash-verified

110}
111
112function getException(
113 client: Client,
114 mechanism: Mechanism,
115 exception: unknown,
116 hint?: EventHint,
117): [Error, Extras | undefined] {
118 if (isError(exception)) {
119 return [exception, undefined];
120 }
121
122 // Mutate this!
123 mechanism.synthetic = true;
124
125 if (isPlainObject(exception)) {
126 const normalizeDepth = client?.getOptions().normalizeDepth;
127 const extras = { ['__serialized__']: normalizeToSize(exception, normalizeDepth) };
128
129 const errorFromProp = getErrorPropertyFromObject(exception);
130 if (errorFromProp) {
131 return [errorFromProp, extras];
132 }
133
134 const message = getMessageForObject(exception);
135 const ex = hint?.syntheticException || new Error(message);
136 ex.message = message;
137
138 return [ex, extras];
139 }
140
141 // This handles when someone does: `throw "something awesome";`
142 // We use synthesized Error here so we can extract a (rough) stack trace.
143 const ex = hint?.syntheticException || new Error(exception as string);
144 ex.message = `${exception}`;
145
146 return [ex, undefined];
147}
148
149/**
150 * Builds and Event from a Exception

Callers 1

eventFromUnknownInputFunction · 0.85

Calls 6

isErrorFunction · 0.90
isPlainObjectFunction · 0.90
normalizeToSizeFunction · 0.90
getMessageForObjectFunction · 0.85
getOptionsMethod · 0.65

Tested by

no test coverage detected