Skip to content

fix: Only add pre/post context if possible #1458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions packages/node/src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ function getModule(filename: string, base?: string): string {
// To be a part of main module, it has to share the same base
n = `${filename}/`.lastIndexOf(base, 0);
if (n === 0) {
let module = filename.substr(base.length).replace(/\//g, '.');
if (module) {
module += ':';
let moduleName = filename.substr(base.length).replace(/\//g, '.');
if (moduleName) {
moduleName += ':';
}
module += file;
return module;
moduleName += file;
return moduleName;
}
return file;
}
Expand Down Expand Up @@ -133,8 +133,23 @@ export async function parseStack(stack: stacktrace.StackFrame[]): Promise<StackF
return parsedFrame;
});

const sourceFiles = await readSourceFiles(filesToRead);
try {
return addPrePostContext(filesToRead, frames);
} 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 frames;
}
}

/**
* This function tries to read the source files + adding pre and post context (source code)
* to a frame.
* @param filesToRead string[] of filepaths
* @param frames StackFrame[] containg all frames
*/
async function addPrePostContext(filesToRead: string[], frames: StackFrame[]): Promise<StackFrame[]> {
const sourceFiles = await readSourceFiles(filesToRead);
return frames.map(frame => {
if (frame.filename && sourceFiles[frame.filename]) {
try {
Expand Down