Description
Version
3.1.1
Reproduction link
https://jsfiddle.net/Lom7hxn5/
Steps to reproduce
- Call
$router.replace
or$router.push
twice with same path
What is expected?
Error object provides stacktrace (stack property)
What is actually happening?
No stack trace in the error object
When NavigationDuplicated
error is thrown, there is no stack trace in the error itself so when error is reported through error reporting service like Sentry
, there is absolutely no context to go with the error and so it's hard to figure out where that error originated.
Transpiled code for the NavigationDuplicated
class looks like this:
vue-router/dist/vue-router.common.js
Lines 1935 to 1946 in 5141def
which is problematic because instantiating such function won't create a stacktrace. It would work fine with non-transpiled code (although I'm not suggesting to not transpile it):
vue-router/src/history/errors.js
Line 1 in 44c63a9
One possible solution would be to manually set stack trace with:
this.stack = (new Error()).stack;
but I'm not sure how that would be done if transpilation is done by webpack/babel...
There is also one extra bug in that code. The line that instantiates error passes a route object to the error:
vue-router/src/history/base.js
Line 125 in fc42d9c
but error doesn't do anything with it:
vue-router/src/history/errors.js
Line 2 in 44c63a9
Saving route properties on the error object would also help in deciphering source of the error.