emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.47k stars 4.21k forks source link

Errors in .then callback get swallowed #3232

Closed FoxGit closed 11 years ago

FoxGit commented 11 years ago

Hi,

Ember: Ember RC6 Ember-data: ember-data-ed99201d561c090fa95cc8739c40bac372924109

Apologies for not using the latest version but I do not have time to upgrade right now. Even more apologies if the error is not still present the latest version. :( I experienced a nasty behavior trying to set a variable in a callback waiting for a list to be populated. The error gets swallowed, the callback function is exited silently and it took quite some time to figure out what is going on.

someView.extend({ ... //this attribute will update a template status: false, doStuff: function() {

    var
    stuffElements = this.get('content');

    stuffElements.forEach(function(formular) {
        stuff.then (function(){
            //there is no "foo"
            foo.set('bar', foobar);
            console.log("this will never be called");
        });
    };
});
...
});

Ember goes into reject(promise, error) in the "rsvp/promise" module but the error is not bubbled up. This may be fixed during https://github.com/emberjs/ember.js/pull/2872 ?

Thanks

stefanpenner commented 11 years ago

then/promises have this property. You must listen to errors or they will be swallowed,

then(function(){ /* */ }).catch(RSVP.rethrow); 

Another option is to use RSVP.on('error') hook.

Much much much regarding this issue: https://github.com/promises-aplus/promises-spec/issues/43

We are planning many improvements in this domain, including improved tooling, and improved semantics.

FoxGit commented 11 years ago

Thx for the fast response. I will use the error handler for now.

stefanpenner commented 10 years ago

an update. ember how ships with a sane RSVP.on('error') handle that's prevents normally swallowed exceptions from going totally un-noticed.