router: Configuring a route with "redirect" property causes BlueBird warnings

I’m submitting a bug report

  • Library Version: 1.0.1

Please tell us about your environment:

  • Operating System: Windows 10

  • Browser: all

  • Language: all

Current behavior: specifying “redirect” property in a route configuration, causes BlueBird warnings about “Warning: a promise was rejected with a non-error: [object Object]”

This comes from the router method:

  function _buildNavigationPlan(instruction, forceLifecycleMinimum) {
    var prev = instruction.previousInstruction;
    var config = instruction.config;
    var plan = {};

    if ('redirect' in config) {
      var redirectLocation = _resolveUrl(config.redirect, getInstructionBaseUrl(instruction));
      if (instruction.queryString) {
        redirectLocation += '?' + instruction.queryString;
      }

      return Promise.reject(new Redirect(redirectLocation));
    }

I tired creating a gist given the link in the Issue Template, however i can’t replicate it in a Gist - i’m assuming the bluebird promises library isn’t included in gists?

Expected/desired behavior: Not to create a warning in the console everytime that specific route is redirected

  • What is the motivation / use case for changing the behavior? Less warnings in the console

I understand that this is a BlueBird “quirk”, however I’m posing the question as to whether Aurelia adjusts its use of BlueBird to stop these warnings? or if we need to go to BlueBird and propose a “don’t warn me when a promise is rejected with a non-error” flag?

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 4
  • Comments: 23 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Updates on this? This has been bugging me for a while now.

Is there really nothing else we can do except disable all warnings?

@ry8806 I agree - it’s not ideal. In our app we’re using environment variables to turn on warnings only for debugging.

Looking at the w3 specification Promise.reject should return an Error object:

The w3 specification for Promises recommends that reject return an instance of Error. https://www.w3.org/2001/tag/doc/promises-guide#reasons-should-be-errors

Promise rejection reasons should always be instances of the ECMAScript Error type, just like synchronously-thrown exceptions should always be instances of Error as well.

Bluebird’s docs explain why: https://github.com/petkaantonov/bluebird/blob/master/docs/docs/warning-explanations.md

Due to a historic mistake in JavaScript, the throw statement is allowed to be used with any value, not just errors, and Promises/A+ choosing to inherit this mistake, it is possible to reject a promise with a value that is not an error.

The only way to stop the console warnings is to change the code to return an Error or not use Promise.reject for redirection.

@EisenbergEffect - What are your thoughts?

I get this is a low profile issue but could we get an official response on whether we should expect this to be handled or if the only workaround is to disable warning?

Technically-shmecnically It works? don’t change it! (-: How’s that for an argument?

If you don’t want these to show then you need to disable them in your bluebird config:

If you’re using Aurelia CLI you can change it within the main.js file.

Promise.config({
  warnings: false
});

The fix introduced in 487c33d50fa938c9e725180877f6510ecae89db5 causes a much more serious error when redirecting in a sub-router config: TypeError: Cannot read property 'childRouter' of undefined is thrown because determineWhatToLoad(…) tries to interpret the Redirect plan as a regular plan because the rejection needs to be handled in more places than just the one checked in 487c33d50fa938c9e725180877f6510ecae89db5.

Technically it’s an uncaught error, and that’s certainly not a good thing.

@Kukks for the record, the problem is just a warning being logged to the console?

I think a good, viable long term fix would be to allow resolving a redirect as well. I agree that while the reject notation half makes sense, it half doesn’t. PRs welcome if someone wants to take a stab at that.

@jagonalez I’m aware of this, thanks

This “silence all warnings” flag isn’t the solution, by disabling ALL warnings (for the issue mentioned above) I might be losing out on other warnings that it may be trying to warn me about