@@ -3,20 +3,14 @@ import { Event, EventProcessor, Integration } from '@sentry/types';
3
3
import { addContextToFrame } from '@sentry/utils' ;
4
4
import { readFile } from 'fs' ;
5
5
import { LRUMap } from 'lru_map' ;
6
+ import { promisify } from 'util' ;
6
7
7
8
import { NodeClient } from '../client' ;
8
9
9
10
const FILE_CONTENT_CACHE = new LRUMap < string , string | null > ( 100 ) ;
10
11
const DEFAULT_LINES_OF_CONTEXT = 7 ;
11
12
12
- function readTextFileAsync ( path : string ) : Promise < string > {
13
- return new Promise ( ( resolve , reject ) => {
14
- readFile ( path , 'utf8' , ( err , data ) => {
15
- if ( err ) reject ( err ) ;
16
- else resolve ( data ) ;
17
- } ) ;
18
- } ) ;
19
- }
13
+ const readFileAsync = promisify ( readFile ) ;
20
14
21
15
/**
22
16
* Resets the file cache. Exists for testing purposes.
@@ -28,10 +22,11 @@ export function resetFileContentCache(): void {
28
22
29
23
interface ContextLinesOptions {
30
24
/**
31
- * Sets the number of context lines for each frame when loading a file
25
+ * Sets the number of context lines for each frame when loading a file.
26
+ * Defaults to 7.
32
27
*
33
28
* Set to 0 to disable loading and inclusion of source files.
34
- * */
29
+ **/
35
30
frameContextLines ?: number ;
36
31
}
37
32
@@ -125,7 +120,7 @@ async function readSourceFiles(filenames: Set<string>): Promise<Record<string, s
125
120
126
121
let content : string | null = null ;
127
122
try {
128
- content = await readTextFileAsync ( filename ) ;
123
+ content = await readFileAsync ( filename , { encoding : 'utf8' } ) ;
129
124
} catch ( _ ) {
130
125
//
131
126
}
0 commit comments