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

Angular 1.6 - Possibly unhandled rejection: canceled #5890

Closed
achenxp opened this issue Dec 14, 2016 · 76 comments
Closed

Angular 1.6 - Possibly unhandled rejection: canceled #5890

achenxp opened this issue Dec 14, 2016 · 76 comments
Milestone

Comments

@achenxp
Copy link

achenxp commented Dec 14, 2016

Click on column header to sort data and it throws "Possibly unhandled rejection: canceled" error under Angular 1.6.

http://plnkr.co/edit/bXEXwcvHz1dK655nHpeT?p=preview

@mportuga
Copy link
Member

angular 1.6 is currently not supported by UI-Grid, but thank you for the information

@mportuga mportuga added this to the Future milestone Dec 14, 2016
@vincent-ollivier-everysens

+1
Error throws immediatly at load with Angular 1.6

@sebastian-zarzycki-apzumi

This is a result of timeout.cancel (about 8 times in code). UI-Grid creates own promise with .then(), right after defining the cancel. This is the main offender, but there are others:

 Grid.prototype.queueRefresh = function queueRefresh() {
                    var self = this;

                    if (self.refreshCanceller) {
                        $timeout.cancel(self.refreshCanceller);
                    }

                    self.refreshCanceller = $timeout(function () {
                        self.refreshCanvas(true);
                    });

                    self.refreshCanceller.then(function () {
                        self.refreshCanceller = null;
                    });

                    return self.refreshCanceller;
                };

simple change to the then part to

self.refreshCanceller.then(function () {
                        self.refreshCanceller = null;
                    }, angular.noop)

@paambaati
Copy link

For anyone that wants a workaround (not recommended, though), you can globally silence unhandled promise rejections like this —

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);

@dominusbelial
Copy link
Contributor

sebastian-zarzycki-es solution prevents the "Possibly unhandled rejection: canceled" error but the offending code should be rewritten to prevent hiding possible errors.

@sebastian-zarzycki-apzumi

Can $timeout.cancel ever throw an error?

@Nickproger
Copy link
Contributor

+1
Same problem... Waiting for it...

@ivorobkalo
Copy link

+1
the same

@dominusbelial
Copy link
Contributor

dominusbelial commented Dec 21, 2016

not sure about that sebastian but angular 1.6.0 conforms to promises/a+ so proper handling should look like you suggested $promise.then(() => {},angular.noop) or $promise.then().catch() else we get the "Possibly unhandled rejection: canceled", notice you should prefer the latter as 1.6.0 migration suggest... https://docs.angularjs.org/guide/migration#migrate1.5to1.6-ng-services-$http

@sebastian-zarzycki-apzumi

Yes, I agree. All I'm saying is that the error response will probably never trigger anyway in this case, so angular.noop will do just fine. But, yeah, using proper then().catch() is better, even if catch would be empty.

@valdirviana
Copy link

+1
Same problem with ui-grid

@mkjois
Copy link

mkjois commented Dec 29, 2016

I tried using the $qProvider.errorOnUnhandledRejections(false) config on just the module that encapsulates my ui-grid, but it turns out that providers are singletons and this affects all of my modules that use $q.

Is there a way to have the one module use a sort of "separate $q" where I could ignore the unhandled rejections in that module only? Or any better workarounds?

@mkjois
Copy link

mkjois commented Dec 29, 2016

@sebastian-zarzycki-es Could you point out where in the code you found that block? I might have to tackle this myself

@sebastian-zarzycki-apzumi

Just search for $timeout.cancel and look for any .then() connected to them in near, as they create new promise, that has to handle the error part with catch.

@bostondevin
Copy link

+1 support angular 1.6

@dominusbelial
Copy link
Contributor

using sebastian-zarzycki-es solution i have added ".catch(angular.noop)" to all the offending promises on the latest 4.0.2 uigrid for angular 1.6.1... all features are working for my implementation and not getting the Possibly unhandled rejection: canceled...
ui-grid.zip

@mkjois
Copy link

mkjois commented Jan 3, 2017

@dominusbelial Do you happen to have your fix on a GitHub repo?

@mportuga
Copy link
Member

mportuga commented Jan 4, 2017

We are willing to accepts pull requests for this fix

@mportuga mportuga closed this as completed Jan 4, 2017
@mportuga mportuga reopened this Jan 4, 2017
@cybermerlin
Copy link
Contributor

in branch i fixed this trouble

@jasonwr
Copy link

jasonwr commented Jan 13, 2017

@cybermerlin I just tested out the window.setTimeout from your branch and the problem still remains when I click on a column header to sort by column.

@dominusbelial
Copy link
Contributor

forked and updated in my branch

@mattbrunetti
Copy link

@dominusbelial Put in a PR? 😄

@dominusbelial
Copy link
Contributor

@mattbrunetti will do, this is my first time!

@Sheeryada
Copy link

+1

2 similar comments
@l8nites
Copy link

l8nites commented Feb 7, 2017

+1

@takotuesday
Copy link

+1

@masterOL
Copy link

masterOL commented Mar 7, 2017

+1

2 similar comments
@hendriklammers
Copy link

+1

@YahiaDev
Copy link

+1

@YahiaDev
Copy link

Any news about the new version ?

@derekm
Copy link

derekm commented Mar 14, 2017

The proposed fix is quite a hack. It fixes one NPE and then tacks a bunch of empty .catch()s onto everything. Seems like a silly thing for Angular 1.6 to impose on projects.

@mattbrunetti
Copy link

I agree with @derekm.. the proposed fix seems pretty wrong. There must be a solution that doesn't simply swallow all unhandled rejections, which is pretty reckless.

@sebastian-zarzycki-apzumi

Whoa, these comments. Does anyone even know how Angular works?

Angular's $timeout returns promise and all they did was just add a warning to all promises that do not have both results handled. In case of $timeout this is just redundant, because $timeout itself cannot ever result with an error and if you cancel it manually, you care even less. Take a look at Angular's $timeout.cancel implementation:

 timeout.cancel = function(promise) {
      if (promise && promise.$$timeoutId in deferreds) {
        // Timeout cancels should not report an unhandled promise.
        deferreds[promise.$$timeoutId].promise.catch(noop);
        deferreds[promise.$$timeoutId].reject('canceled');
        delete deferreds[promise.$$timeoutId];
        return $browser.defer.cancel(promise.$$timeoutId);
      }
      return false;
    };

Does that comment ring any bell?

@dgsmith2
Copy link

I fear this is going to turn into a flame war, but I personally DO agree with the changes.

By supplying a .then(handleTheGood) you are implicitly supplying a .noop rejection callback. Angular 1.6 now encourages developers to be explicit in handling either outcome of a promise. In 1.6 if a promise you expected to always resolve for some reason didn't you get information (i.e., error message in the console) about an unhandled rejection that you should obviously be handling.

Also, if you are coding promises according to spec, you aren't using the .finally that $q provides and therefore already handling rejections explicitly, even if they are simply a .noop to achieve a "finally". (.then(handleTheGood, handleTheBad).then(handleRegardless) or .then(handleTheGood).catch(handleTheBad).then(handleRegardless, with both assuming your handleTheBad doesn't return a rejected promise)

@Oceanswave
Copy link

Oceanswave commented Mar 14, 2017

Angular now warns us when there's an unhandled rejection, we don't want to shut that off globally, but we also don't like the solution that suppresses unhandled rejections in situations that an unhandled rejection is not important in cases where the promise is part of the library and can't be controlled by the developer.

wut?

@niveditapatil
Copy link

Any idea about when is ui-grid planning to support Angular JS 1.6 version?

@DoubleDot
Copy link

Any update on this?

@alinleonard
Copy link

alinleonard commented Apr 6, 2017

+1

@MatejQ
Copy link
Contributor

MatejQ commented Apr 7, 2017

I don't know whether ui-grid already handles these cases but if not, you can configure angular to ignore unhandled promise rejections (reverting to pre-1.6.0 behavior).
(typescript code following)

        App.AppModule.config([
            "$qProvider",
            ($qProvider: any) => { // Q Provider is not part of .d.ts for some reason
                // suppress angular errors about unhandled promise rejections since 1.6.0
                $qProvider.errorOnUnhandledRejections(false);
            }
        ]);

@adrienplg
Copy link

+1

@SensationSama
Copy link

See angular-ui/ui-router#3246

@7urkm3n
Copy link

7urkm3n commented Apr 21, 2017

+1

@ITAndy23
Copy link

I get the same error running the ui-grid for the first time using Angular 1.6.4.
What's the recommendation to work around it? Revert to an earlier version of Angular?

@mohanrao
Copy link

+1

6 similar comments
@jasonwr
Copy link

jasonwr commented Apr 28, 2017

+1

@mmaask
Copy link

mmaask commented Apr 30, 2017

+1

@michelj90
Copy link

+1

@doracl
Copy link

doracl commented May 4, 2017

+1

@jspencersharpe
Copy link

+1

@pwdl
Copy link

pwdl commented Jul 12, 2017

+1

@kyleThayerXpanxion
Copy link

+1!!

@cybermerlin
Copy link
Contributor

fixed this trouble in

https://github.com/cybermerlin/ui-grid/tree/develop

@GlennHogent
Copy link

+1

1 similar comment
@besil
Copy link

besil commented Oct 15, 2017

+1

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

No branches or pull requests