-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): Decode filename
and module
stack frame properties in Node stack parser
#14544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
197dac0
fix(core): Decode file name in Node stack parser
Lms24 d1c2f2e
add esm integration test
Lms24 42dd055
add more tests
Lms24 3174ae2
also decode module field
Lms24 5000272
formatting
Lms24 6d7f196
skip esm for Node 14, 16
Lms24 09fb5c5
formatting once more
Lms24 681b591
fix integration tests
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/contextLines/instrument.mjs
This file contains hidden or 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,9 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
autoSessionTracking: false, | ||
transport: loggingTransport, | ||
}); |
13 changes: 13 additions & 0 deletions
13
dev-packages/node-integration-tests/suites/contextLines/scenario with space.cjs
This file contains hidden or 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,13 @@ | ||
const Sentry = require('@sentry/node'); | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
autoSessionTracking: false, | ||
transport: loggingTransport, | ||
}); | ||
|
||
Sentry.captureException(new Error('Test Error')); | ||
|
||
// some more post context |
5 changes: 5 additions & 0 deletions
5
dev-packages/node-integration-tests/suites/contextLines/scenario with space.mjs
This file contains hidden or 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,5 @@ | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.captureException(new Error('Test Error')); | ||
|
||
// some more post context |
83 changes: 83 additions & 0 deletions
83
dev-packages/node-integration-tests/suites/contextLines/test.ts
This file contains hidden or 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,83 @@ | ||
import { join } from 'path'; | ||
import { conditionalTest } from '../../utils'; | ||
import { createRunner } from '../../utils/runner'; | ||
|
||
conditionalTest({ min: 18 })('ContextLines integration in ESM', () => { | ||
test('reads encoded context lines from filenames with spaces', done => { | ||
expect.assertions(1); | ||
const instrumentPath = join(__dirname, 'instrument.mjs'); | ||
|
||
createRunner(__dirname, 'scenario with space.mjs') | ||
.withFlags('--import', instrumentPath) | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
value: 'Test Error', | ||
stacktrace: { | ||
frames: expect.arrayContaining([ | ||
{ | ||
filename: expect.stringMatching(/\/scenario with space.mjs$/), | ||
context_line: "Sentry.captureException(new Error('Test Error'));", | ||
pre_context: ["import * as Sentry from '@sentry/node';", ''], | ||
post_context: ['', '// some more post context'], | ||
colno: 25, | ||
lineno: 3, | ||
function: '?', | ||
in_app: true, | ||
module: 'scenario with space', | ||
}, | ||
]), | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
}); | ||
|
||
describe('ContextLines integration in CJS', () => { | ||
test('reads context lines from filenames with spaces', done => { | ||
expect.assertions(1); | ||
|
||
createRunner(__dirname, 'scenario with space.cjs') | ||
.expect({ | ||
event: { | ||
exception: { | ||
values: [ | ||
{ | ||
value: 'Test Error', | ||
stacktrace: { | ||
frames: expect.arrayContaining([ | ||
{ | ||
filename: expect.stringMatching(/\/scenario with space.cjs$/), | ||
context_line: "Sentry.captureException(new Error('Test Error'));", | ||
pre_context: [ | ||
'Sentry.init({', | ||
" dsn: 'https://public@dsn.ingest.sentry.io/1337',", | ||
" release: '1.0',", | ||
' autoSessionTracking: false,', | ||
' transport: loggingTransport,', | ||
'});', | ||
'', | ||
], | ||
post_context: ['', '// some more post context'], | ||
colno: 25, | ||
lineno: 11, | ||
function: 'Object.?', | ||
in_app: true, | ||
module: 'scenario with space', | ||
}, | ||
]), | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
import { createGetModuleFromFilename } from '../../src'; | ||
|
||
describe('createGetModuleFromFilename', () => { | ||
it.each([ | ||
['/path/to/file.js', 'file'], | ||
['/path/to/file.mjs', 'file'], | ||
['/path/to/file.cjs', 'file'], | ||
['file.js', 'file'], | ||
])('returns the module name from a filename %s', (filename, expected) => { | ||
const getModule = createGetModuleFromFilename(); | ||
expect(getModule(filename)).toBe(expected); | ||
}); | ||
|
||
it('applies the given base path', () => { | ||
const getModule = createGetModuleFromFilename('/path/to/base'); | ||
expect(getModule('/path/to/base/file.js')).toBe('file'); | ||
}); | ||
|
||
it('decodes URI-encoded file names', () => { | ||
const getModule = createGetModuleFromFilename(); | ||
expect(getModule('/path%20with%space/file%20with%20spaces(1).js')).toBe('file with spaces(1)'); | ||
}); | ||
|
||
it('returns undefined if no filename is provided', () => { | ||
const getModule = createGetModuleFromFilename(); | ||
expect(getModule(undefined)).toBeUndefined(); | ||
}); | ||
|
||
it.each([ | ||
['/path/to/base/node_modules/@sentry/test/file.js', '@sentry.test:file'], | ||
['/path/to/base/node_modules/somePkg/file.js', 'somePkg:file'], | ||
])('handles node_modules file paths %s', (filename, expected) => { | ||
const getModule = createGetModuleFromFilename(); | ||
expect(getModule(filename)).toBe(expected); | ||
}); | ||
|
||
it('handles windows paths with passed basePath and node_modules', () => { | ||
const getModule = createGetModuleFromFilename('C:\\path\\to\\base', true); | ||
expect(getModule('C:\\path\\to\\base\\node_modules\\somePkg\\file.js')).toBe('somePkg:file'); | ||
}); | ||
|
||
it('handles windows paths with default basePath', () => { | ||
const getModule = createGetModuleFromFilename(undefined, true); | ||
expect(getModule('C:\\path\\to\\base\\somePkg\\file.js')).toBe('file'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change also includes a tiny refactor to use a template string instead of concatenation. I made the change after writing the tests btw, so this should be fine