Skip to content

Conversation

@davewasmer
Copy link

Some sourcemap tools can produce absolute paths for source map urls, which will then be reflected in error stacktraces that feature absolute paths for the stack frame source url.

Previously, the basePath (typically process.cwd()) was prefixed to all error stacktrace urls, which sometimes works for relative paths[1], but will fail with absolute paths.

This change checks if the stacktrace url is absolute first - if so, it skips prefixing the url with basePath.

This change is more than cosmetic - the mini reporter uses the stacktrace url to invoke the codeExcerpt helper, which tries to load the source file from that url. If it's not correct, codeExcerpt will throw.


[1] - See #1266. Intermediate build steps between the sourcemap generation and running ava can break relative urls too. This change does not solve that problem - it only fixes the absolute path scenario.

@novemberborn
Copy link
Member

Hi @davewasmer. This is similar to #1246. We've decided to ensure error.source.file is an absolute path so the reporters don't have to deal with this. I'm working on that at the moment.

Thanks for opening this pull request. Keep them coming 😄

@davewasmer
Copy link
Author

@novemberborn thanks for the quick response!

Just out of curiosity - how do you plan to get the absolute source url for files that have relative sourcemaps? I didn't see a way around that one, so I'm curious what you've come up with.

@novemberborn
Copy link
Member

Just out of curiosity - how do you plan to get the absolute source url for files that have relative sourcemaps? I didn't see a way around that one, so I'm curious what you've come up with.

See #1271. I'm basically assuming that V8 and any source map library make them relative to the working directory. It's best effort, really.

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.

2 participants