Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): Exception[] {
if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
return stack;
}
const stacktrace = computeStackTrace(error[key]);
const exception = exceptionFromStacktrace(stacktrace);
return this._walkErrorTree(error[key], key, [exception, ...stack]);
}
}
public walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): PromiseLike {
if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
return SyncPromise.resolve(stack);
}
return new SyncPromise((resolve, reject) => {
getExceptionFromError(error[key])
.then((exception: Exception) => {
this.walkErrorTree(error[key], key, [exception, ...stack])
.then(resolve)
.then(null, () => {
reject();
});
})
.then(null, () => {
reject();
});
});
}
function isSpanInstance(span: unknown): span is Span {
return isInstanceOf(span, Span);
}
public handler(event: Event, hint?: EventHint): PromiseLike {
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
return SyncPromise.resolve(event);
}
return new SyncPromise(resolve => {
this.walkErrorTree(hint.originalException as Error, this._key)
.then((linkedErrors: Exception[]) => {
if (event && event.exception && event.exception.values) {
event.exception.values = [...linkedErrors, ...event.exception.values];
}
resolve(event);
})
.then(null, () => {
resolve(event);
});
});
}
private _handler(event: Event, hint?: EventHint): Event | null {
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
return event;
}
const linkedErrors = this._walkErrorTree(hint.originalException as ExtendedError, this._key);
event.exception.values = [...linkedErrors, ...event.exception.values];
return event;
}
public constructor(spanContext?: SpanContext, hub?: Hub) {
if (isInstanceOf(hub, Hub)) {
this._hub = hub as Hub;
}
if (!spanContext) {
return this;
}
if (spanContext.traceId) {
this._traceId = spanContext.traceId;
}
if (spanContext.spanId) {
this._spanId = spanContext.spanId;
}
if (spanContext.parentSpanId) {
this._parentSpanId = spanContext.parentSpanId;
}