Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
return parsedFrame;
});
// We do an early return if we do not want to fetch context liens
if (linesOfContext <= 0) {
return SyncPromise.resolve(frames);
}
try {
return addPrePostContext(filesToRead, frames, linesOfContext);
} catch (_) {
// This happens in electron for example where we are not able to read files from asar.
// So it's fine, we recover be just returning all frames without pre/post context.
return SyncPromise.resolve(frames);
}
}
function readSourceFiles(filenames: string[]): PromiseLike<{ [key: string]: string | null }> {
// we're relying on filenames being de-duped already
if (filenames.length === 0) {
return SyncPromise.resolve({});
}
return new SyncPromise<{
[key: string]: string | null;
}>(resolve => {
const sourceFiles: {
[key: string]: string | null;
} = {};
let count = 0;
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < filenames.length; i++) {
const filename = filenames[i];
const cache = FILE_CONTENT_CACHE.get(filename);
// We have a cache hit
exception.value = truncate(exception.value, maxValueLength);
}
const request = prepared.request;
if (request && request.url) {
request.url = truncate(request.url, maxValueLength);
}
if (prepared.event_id === undefined) {
prepared.event_id = uuid4();
}
this._addIntegrations(prepared.sdk);
// We prepare the result here with a resolved Event.
let result = SyncPromise.resolve(prepared);
// This should be the last thing called, since we want that
// {@link Hub.addEventProcessor} gets the finished prepared event.
if (scope) {
// In case we have a hub we reassign it.
result = scope.applyToEvent(prepared, hint);
}
return result;
}
public eventFromException(exception: any, hint?: EventHint): PromiseLike {
const syntheticException = (hint && hint.syntheticException) || undefined;
const event = eventFromUnknownInput(exception, syntheticException, {
attachStacktrace: this._options.attachStacktrace,
});
addExceptionMechanism(event, {
handled: true,
type: 'generic',
});
event.level = Severity.Error;
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
return SyncPromise.resolve(event);
}
/**
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike {
const syntheticException = (hint && hint.syntheticException) || undefined;
const event = eventFromString(message, syntheticException, {
attachStacktrace: this._options.attachStacktrace,
});
event.level = level;
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
return SyncPromise.resolve(event);
}
}
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();
});
});
}
}
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);
});
});
}
public close(_?: number): PromiseLike {
return SyncPromise.resolve(true);
}
}