MCPcopy Index your code
hub / github.com/angular/angular / ZoneAwareError

Function ZoneAwareError

packages/zone.js/lib/common/error-rewrite.ts:118–160  ·  view source on GitHub ↗

* This is ZoneAwareError which processes the stack frame and cleans up extra frames as well as * adds zone information to it.

(this: unknown | typeof NativeError)

Source from the content-addressed store, hash-verified

116 * adds zone information to it.
117 */
118 function ZoneAwareError(this: unknown | typeof NativeError): Error {
119 // We always have to return native error otherwise the browser console will not work.
120 let error: Error = NativeError.apply(this, arguments);
121 // Save original stack trace
122 const originalStack = ((error as any)['originalStack'] = error.stack);
123
124 // Process the stack trace and rewrite the frames.
125 if ((ZoneAwareError as any)[stackRewrite] && originalStack) {
126 let zoneFrame = api.currentZoneFrame();
127 if (zoneJsInternalStackFramesPolicy === 'lazy') {
128 // don't handle stack trace now
129 (error as any)[api.symbol('zoneFrameNames')] = buildZoneFrameNames(zoneFrame);
130 } else if (zoneJsInternalStackFramesPolicy === 'default') {
131 try {
132 error.stack = error.zoneAwareStack = buildZoneAwareStackFrames(
133 originalStack,
134 zoneFrame,
135 );
136 } catch (e) {
137 // ignore as some browsers don't allow overriding of stack
138 }
139 }
140 }
141
142 if (this instanceof NativeError && this.constructor != NativeError) {
143 // We got called with a `new` operator AND we are subclass of ZoneAwareError
144 // in that case we have to copy all of our properties to `this`.
145 Object.keys(error)
146 .concat('stack', 'message', 'cause')
147 .forEach((key) => {
148 const value = (error as any)[key];
149 if (value !== undefined) {
150 try {
151 this[key] = value;
152 } catch (e) {
153 // ignore the assignment in case it is a setter and it throws.
154 }
155 }
156 });
157 return this;
158 }
159 return error;
160 }
161
162 // Copy the prototype so that instanceof operator works as expected
163 ZoneAwareError.prototype = NativeError.prototype;

Callers

nothing calls this directly

Calls 6

buildZoneFrameNamesFunction · 0.85
applyMethod · 0.65
symbolMethod · 0.65
keysMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…