-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): Don't overwrite local variables for re-thrown errors (#13644)
Another way to fix this issue would be to check via the debugger if the property exists already on the error object and bail early before we have local variables. However, this would add an extra round trip call via the debugger for every error. Since re-thrown errors are far less likely, I decided instead to just not overwrite existing local variables. This PR also adds a `Debugger.resume` call in the catch case to ensure that they debugger will always resume even if we get errors while debugging. It's worth noting that this only fixes the issue in Node v20+ where we use the async debugging interface.
- Loading branch information
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ckages/node-integration-tests/suites/public-api/LocalVariables/local-variables-rethrow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable no-unused-vars */ | ||
const Sentry = require('@sentry/node'); | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
includeLocalVariables: true, | ||
transport: loggingTransport, | ||
}); | ||
|
||
class Some { | ||
two(name) { | ||
throw new Error('Enough!'); | ||
} | ||
} | ||
|
||
function one(name) { | ||
const arr = [1, '2', null]; | ||
const obj = { | ||
name, | ||
num: 5, | ||
}; | ||
const bool = false; | ||
const num = 0; | ||
const str = ''; | ||
const something = undefined; | ||
const somethingElse = null; | ||
|
||
const ty = new Some(); | ||
|
||
ty.two(name); | ||
} | ||
|
||
setTimeout(() => { | ||
try { | ||
try { | ||
one('some name'); | ||
} catch (e) { | ||
const more = 'here'; | ||
throw e; | ||
} | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
} | ||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters