-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
Version
3.1.1
Reproduction link
https://jsfiddle.net/Lom7hxn5/
Steps to reproduce
- Call
$router.replaceor$router.pushtwice 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
| var NavigationDuplicated = /*@__PURE__*/(function (Error) { | |
| function NavigationDuplicated () { | |
| Error.call(this, 'Navigating to current location is not allowed'); | |
| this.name = this._name = 'NavigationDuplicated'; | |
| } | |
| if ( Error ) NavigationDuplicated.__proto__ = Error; | |
| NavigationDuplicated.prototype = Object.create( Error && Error.prototype ); | |
| NavigationDuplicated.prototype.constructor = NavigationDuplicated; | |
| return NavigationDuplicated; | |
| }(Error)); |
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
| export class NavigationDuplicated extends Error { |
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
| return abort(new NavigationDuplicated(route)) |
but error doesn't do anything with it:
vue-router/src/history/errors.js
Line 2 in 44c63a9
| constructor () { |
Saving route properties on the error object would also help in deciphering source of the error.