Skip to content
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

Support Windows-style path in RewriteFrame's default iteratee #2319

Closed
wants to merge 1 commit into from
Closed

Support Windows-style path in RewriteFrame's default iteratee #2319

wants to merge 1 commit into from

Conversation

nfrasser
Copy link
Contributor

The previous default iteratee does not work in Windows because it only detects paths that begin with /. This change ensures paths that begin with C:\\ are also accounted for.

The previous default iteratee does not work in Windows because it only detects
paths that begin with `/`. This change ensures paths that begin with `C:\\` are
also accounted for.

This implementation requires that the specified `root` uses Unix-style paths.
So this will not work:

    new RewriteFrames({
        root: 'C:\\Program Files\\Apache\\www'
    })

But this will:

    new RewriteFrames({
        root: '/Program Files/Apache/www'
    })

Should this behaviour change or be noted in the official docs?
@nfrasser
Copy link
Contributor Author

This implementation requires that the specified root uses Unix-style paths. So this will not work:

new RewriteFrames({
    root: 'C:\\Program Files\\Apache\\www'
})

But this will:

new RewriteFrames({
    root: '/Program Files/Apache/www'
})

Should this behaviour change or be noted in the official docs?

@@ -24,8 +24,12 @@ export class RewriteFrames implements Integration {
* @inheritDoc
*/
private readonly _iteratee: StackFrameIteratee = (frame: StackFrame) => {
if (frame.filename && frame.filename.startsWith('/')) {
const base = this._root ? relative(this._root, frame.filename) : basename(frame.filename);
// Check if the frame filename begins with `/` or a Windows-style prefix such as `C:\\`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows-style prefix is C:\, not C:\\ but the regexp is correct, so just the comment needs a small fix

@kamilogorek
Copy link
Contributor

Yes, the docs update would be awesome!

It has to be changed here https://github.com/getsentry/sentry-docs/blob/7d2b34cde1b7035d3ef1053cd3f746944e01981c/src/collections/_documentation/platforms/node/pluggable-integrations.md#rewriteframes and here https://github.com/getsentry/sentry-docs/blob/f8e6df79e9f9f0151d59e22c870ee8b123e34918/src/collections/_documentation/platforms/javascript/index.md

If you want to send a PR there it'd be great. And at the same time, if you could copy 1:1 the text from Node to JavaScript it'd be even even better (as this one got updated :)). Thanks!

if (frame.filename && /^(\/|[A-Z]:\\)/.test(frame.filename)) {
const filename = frame.filename
.replace(/^[A-Z]:/, '') // remove Windows-style prefix
.replace(/\\/g, '/'); // replace all `\\` instances with `/`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this has a subtle bug, because \ is a valid character in a unix path.

You can have, for example, /tmp/a\b, where a\b is the filename, or the name of a directory on the path above our code. If you do that, this will rewrite it to /tmp/a/b, which probably doesn't exist, and so that'll break things later.

Probably rare, but easy to fix - I think you just want to do these replacements only in the Windows case (where backslashes are not valid in paths), rather than all the time.

@pimterry
Copy link

pimterry commented Dec 4, 2019

I just hit this issue as well, and it's causing me lots of extra noise from error reports in Windows where my path rewriting is broken. I've left one small comment, but regardless this would be super useful for me, it'd be great to get this merged 👍. Let me know if there's anything I can do to help.

@kamilogorek
Copy link
Contributor

Thanks @pimterry updated the code and appropriate tests:

@kamilogorek kamilogorek closed this Dec 9, 2019
@kamilogorek
Copy link
Contributor

Also docs getsentry/sentry-docs#1399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants