Skip to content

Commit 65ea442

Browse files
committed
Simplify a bit more
1 parent d39fe92 commit 65ea442

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

packages/node/src/integrations/localvariables.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,6 @@ function hashFrames(frames: StackFrame[] | undefined): string | undefined {
6262
return frames.reduce((acc, frame) => `${acc},${frame.function},${frame.lineno},${frame.colno}`, '');
6363
}
6464

65-
type HashFromStackFn = (stack: string | undefined) => string | undefined;
66-
67-
/**
68-
* Creates a function used to hash stack strings
69-
*
70-
* We use the stack parser to create a unique hash from the exception stack trace
71-
* This is used to lookup vars when the exception passes through the event processor
72-
*/
73-
function createHashFn(stackParser: StackParser | undefined): HashFromStackFn {
74-
return (stack: string | undefined) => {
75-
if (stackParser === undefined || stack === undefined) {
76-
return undefined;
77-
}
78-
79-
return hashFrames(stackParser(stack, 1));
80-
};
81-
}
82-
8365
interface FrameVariables {
8466
function: string;
8567
vars?: Record<string, unknown>;
@@ -95,6 +77,7 @@ export class LocalVariables implements Integration {
9577

9678
private readonly _session: AsyncSession = new AsyncSession();
9779
private readonly _cachedFrames: LRUMap<string, Promise<FrameVariables[]>> = new LRUMap(50);
80+
private _stackParser: StackParser | undefined;
9881

9982
/**
10083
* @inheritDoc
@@ -103,22 +86,29 @@ export class LocalVariables implements Integration {
10386
const options = getCurrentHub().getClient<NodeClient>()?.getOptions();
10487

10588
if (options?.includeStackLocals) {
106-
this._stackHasher = createHashFn(options.stackParser);
107-
addGlobalEventProcessor(async event => this._addLocalVariables(event));
89+
this._stackParser = options.stackParser;
10890

10991
this._session.connect();
11092
this._session.on('Debugger.paused', this._handlePaused.bind(this));
11193
this._session.post('Debugger.enable');
11294
// We only want to pause on uncaught exceptions
11395
this._session.post('Debugger.setPauseOnExceptions', { state: 'uncaught' });
96+
97+
addGlobalEventProcessor(async event => this._addLocalVariables(event));
11498
}
11599
}
116100

117101
/**
118102
* We use the stack parser to create a unique hash from the exception stack trace
119-
* This is used to lookup vars when the event processor is called
103+
* This is used to lookup vars when the exception passes through the event processor
120104
*/
121-
private _stackHasher: HashFromStackFn = _ => undefined;
105+
private _hashFromStack(stack: string | undefined): string | undefined {
106+
if (this._stackParser === undefined || stack === undefined) {
107+
return undefined;
108+
}
109+
110+
return hashFrames(this._stackParser(stack, 1));
111+
}
122112

123113
/**
124114
* Handle the pause event
@@ -131,7 +121,7 @@ export class LocalVariables implements Integration {
131121
}
132122

133123
// data.description contains the original error.stack
134-
const exceptionHash = this._stackHasher(data?.description);
124+
const exceptionHash = this._hashFromStack(data?.description);
135125

136126
if (exceptionHash == undefined) {
137127
return;
@@ -219,7 +209,7 @@ export class LocalVariables implements Integration {
219209
const frameCount = event?.exception?.values?.[0]?.stacktrace?.frames?.length || 0;
220210

221211
for (let i = 0; i < frameCount; i++) {
222-
// Sentry frames are already in reverse order
212+
// Sentry frames are in reverse order
223213
const frameIndex = frameCount - i - 1;
224214

225215
// Drop out if we run out of frames to match up

0 commit comments

Comments
 (0)