11import type { StackFrame } from 'error-stack-parser' ;
22import ErrorStackParser from 'error-stack-parser' ;
33import type { BacktraceFrame , SourceCodeLine } from '@hawk.so/types' ;
4- import log from '../utils/log' ;
54import fetchTimer from './fetchTimer' ;
65
76/**
@@ -26,7 +25,7 @@ export default class StackParser {
2625 const sourceCode = await this . extractSourceCode ( frame ) ;
2726 const file = frame . fileName !== null && frame . fileName !== undefined ? frame . fileName : '' ;
2827 const line = frame . lineNumber !== null && frame . lineNumber !== undefined ? frame . lineNumber : 0 ;
29-
28+
3029 return {
3130 file,
3231 line,
@@ -132,7 +131,18 @@ export default class StackParser {
132131 * Wait for maximum 2 sec to skip loading big files.
133132 */
134133 this . sourceFilesCache [ fileName ] = fetchTimer ( fileName , 2000 )
135- . then ( ( response ) => response . text ( ) ) ;
134+ . then ( ( response ) => response . text ( ) )
135+ . catch ( ( error ) => {
136+ /**
137+ * Remove failed promise from cache to allow retry
138+ */
139+ delete this . sourceFilesCache [ fileName ] ;
140+
141+ /**
142+ * Re-throw error so it can be caught by try-catch
143+ */
144+ throw error ;
145+ } ) ;
136146
137147 /**
138148 * Dealloc cache when it collects more that 10 files
@@ -146,7 +156,10 @@ export default class StackParser {
146156
147157 return await this . sourceFilesCache [ fileName ] ;
148158 } catch ( error ) {
149- log ( 'Can not load source file. Skipping...' ) ;
159+ /**
160+ * Ensure failed promise is removed from cache
161+ */
162+ delete this . sourceFilesCache [ fileName ] ; // log('Can not load source file. Skipping...');
150163
151164 return null ;
152165 }
0 commit comments