File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -51,12 +51,12 @@ function getModule(filename: string, base?: string): string {
5151 // To be a part of main module, it has to share the same base
5252 n = `${ filename } /` . lastIndexOf ( base , 0 ) ;
5353 if ( n === 0 ) {
54- let module = filename . substr ( base . length ) . replace ( / \/ / g, '.' ) ;
55- if ( module ) {
56- module += ':' ;
54+ let moduleName = filename . substr ( base . length ) . replace ( / \/ / g, '.' ) ;
55+ if ( moduleName ) {
56+ moduleName += ':' ;
5757 }
58- module += file ;
59- return module ;
58+ moduleName += file ;
59+ return moduleName ;
6060 }
6161 return file ;
6262}
@@ -133,8 +133,23 @@ export async function parseStack(stack: stacktrace.StackFrame[]): Promise<StackF
133133 return parsedFrame ;
134134 } ) ;
135135
136- const sourceFiles = await readSourceFiles ( filesToRead ) ;
136+ try {
137+ return addPrePostContext ( filesToRead , frames ) ;
138+ } catch ( _ ) {
139+ // This happens in electron for example where we are not able to read files from asar.
140+ // So it's fine, we recover be just returning all frames without pre/post context.
141+ return frames ;
142+ }
143+ }
137144
145+ /**
146+ * This function tries to read the source files + adding pre and post context (source code)
147+ * to a frame.
148+ * @param filesToRead string[] of filepaths
149+ * @param frames StackFrame[] containg all frames
150+ */
151+ async function addPrePostContext ( filesToRead : string [ ] , frames : StackFrame [ ] ) : Promise < StackFrame [ ] > {
152+ const sourceFiles = await readSourceFiles ( filesToRead ) ;
138153 return frames . map ( frame => {
139154 if ( frame . filename && sourceFiles [ frame . filename ] ) {
140155 try {
You can’t perform that action at this time.
0 commit comments