Skip to content

Commit 0a4ca50

Browse files
committed
Abhi code review
1 parent a7d61df commit 0a4ca50

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

packages/node/src/integrations/contextlines.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ import { Event, EventProcessor, Integration } from '@sentry/types';
33
import { addContextToFrame } from '@sentry/utils';
44
import { readFile } from 'fs';
55
import { LRUMap } from 'lru_map';
6+
import { promisify } from 'util';
67

78
import { NodeClient } from '../client';
89

910
const FILE_CONTENT_CACHE = new LRUMap<string, string | null>(100);
1011
const DEFAULT_LINES_OF_CONTEXT = 7;
1112

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);
2014

2115
/**
2216
* Resets the file cache. Exists for testing purposes.
@@ -28,10 +22,11 @@ export function resetFileContentCache(): void {
2822

2923
interface ContextLinesOptions {
3024
/**
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.
3227
*
3328
* Set to 0 to disable loading and inclusion of source files.
34-
* */
29+
**/
3530
frameContextLines?: number;
3631
}
3732

@@ -125,7 +120,7 @@ async function readSourceFiles(filenames: Set<string>): Promise<Record<string, s
125120

126121
let content: string | null = null;
127122
try {
128-
content = await readTextFileAsync(filename);
123+
content = await readFileAsync(filename, { encoding: 'utf8' });
129124
} catch (_) {
130125
//
131126
}

0 commit comments

Comments
 (0)