Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring a route with "redirect" property causes BlueBird warnings #480

Open
ry8806 opened this issue Mar 21, 2017 · 23 comments
Open

Configuring a route with "redirect" property causes BlueBird warnings #480

ry8806 opened this issue Mar 21, 2017 · 23 comments
Labels

Comments

@ry8806
Copy link

ry8806 commented Mar 21, 2017

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?

@renathoaz
Copy link

The same warning is thrown for:

config.mapUnknownRoutes({ redirect:'home'});

is there any way to suppress it ?

@jagonalez
Copy link
Contributor

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
});

@ry8806
Copy link
Author

ry8806 commented Apr 19, 2017

@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

@jagonalez
Copy link
Contributor

@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?

@indfnzo
Copy link

indfnzo commented Jul 5, 2017

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

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

@cornillemichiel
Copy link

I get why the warning is thrown, and valid, but I don't see why we'd reject a promise to do a redirect.

If we HAVE to use promise rejection, couldnt this issue be solved by inheriting redirects from Error? Or adding the needed property stubs (.stack and .message) to the redirect class?

@Kukks
Copy link

Kukks commented Oct 16, 2017

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?

@eric-914
Copy link

eric-914 commented Feb 5, 2018

I'm now hitting this problem, and would like to know if there's any status change on how to fix it?

@davismj
Copy link
Member

davismj commented Feb 6, 2018

@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.

@fkleuver
Copy link
Member

fkleuver commented Feb 16, 2018

@davismj I've been digging into the router recently and noticed a few places where promises aren't being returned from one internal method to the next.

One example in the app-router, _queueInstruction calls _dequeueInstruction but doesn't return it.

Another one is registerViewPort which calls _dequeueInstruction at the bottom.

So what happens to the promise that's returned by _dequeueInstruction in both cases?

I can't help but wonder if this is intended for some kind of asynchrony, or if this was overlooked at some point? I'm fairly sure that this sort of thing is what causes the promise warnings.

@davismj
Copy link
Member

davismj commented Feb 19, 2018

@fkleuver as I didn't write the code and there aren't a lot of comments, I can't say for sure whether or not the highly async architecture was the right way to go. I've noticed the same things and they seem like a liability to me as well, but they're (a) deep and (b) pervasive, so I'm not in any place to start messing with them.

That said, as far as I understand, this particular issue is caused when aurelia internals reject() Redirects to cancel navigation instead of resolving. This is wrong in the strictest interpretation of promises, in which reject() is the async version of a throw, and bluebird tells anyone who will listen.

@Alexander-Taran
Copy link
Contributor

Can we change this?
Or we can't?
Should we?

Or just keep in mind for vNext?

@fkleuver
Copy link
Member

fkleuver commented Mar 24, 2018

As davismj pointed out, it seems my earlier comment isn't applicable to this specific issue. I'd go with his suggestion to allow redirects to be resolved as being the point of action here.
I seem to recall someone was working on that in another PR but I can't find it right now.

I might take a stab at it if no one else is working on it. Could you double check as you're the one who's on top of the issues? :)

@Alexander-Taran
Copy link
Contributor

I remember too.. there were an issue where a question was asked..
do we really want to fix a warning? when nothing is really broken?
Is it really that easy to distract developers?

@fkleuver
Copy link
Member

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

@Alexander-Taran
Copy link
Contributor

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

@davismj
Copy link
Member

davismj commented Apr 8, 2018

@fkleuver No one is working on it as far as I know.

@rluba
Copy link
Contributor

rluba commented Jun 5, 2018

The fix introduced in 487c33d 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 487c33d.

rluba added a commit to rluba/router that referenced this issue Jun 5, 2018
This causes aurelia#480 to re-appear until a better handling for cancellations exists
@stefan505
Copy link

I concur with @rluba , after doing a "clean" install this morning referencing [email protected] (since Feb 2018), I got [email protected], which is causing the TypeError: Cannot read property 'childRouter' of undefined error. Manually installing [email protected] fixed it though.

@Kukks
Copy link

Kukks commented Jun 19, 2018 via email

@fkleuver
Copy link
Member

Yep agreed, #603 should be merged asap. Sorry for breaking your apps!

@davismj
Copy link
Member

davismj commented Jun 19, 2018

It'll be getting released today.

davismj added a commit that referenced this issue Jun 19, 2018
Fix error introduced in 487c33d (when trying to fix #480)
@ricardograca
Copy link

Shouldn't this be reopened since #597 was reverted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.