Skip to content

No stacktrace on NavigationDuplicated error uncaught in promise #2881

Closed
@rchl

Description

@rchl

Version

3.1.1

Reproduction link

https://jsfiddle.net/Lom7hxn5/

Steps to reproduce

  1. 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:

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):

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:

return abort(new NavigationDuplicated(route))

but error doesn't do anything with it:
constructor () {

Saving route properties on the error object would also help in deciphering source of the error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions