Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Handle exceptions thrown in done handles attached to ProjectManager.getAllFiles #6417

Merged
merged 2 commits into from
Jan 8, 2014

Conversation

iwehrman
Copy link
Contributor

@iwehrman iwehrman commented Jan 8, 2014

ProjectManager.getAllFiles currently returns a new promise to each caller, but if one of the callers attaches a done handler to its promise that throws an exception then no further done handlers attached to later promises returned from getAllFiles are executed. This is because jQuery promises are dumb.

Addresses #6401.

CC @redmunds

@ghost ghost assigned redmunds and jasonsanjose Jan 8, 2014
@jasonsanjose
Copy link
Member

Reviewing

@jasonsanjose
Copy link
Member

You say in the description we currently return a new promise. I think you mean that your PR adds this new behavior right? It looks like the old code would return the same promise for every call.

// If a done handler attached to the returned filtered files promise
// throws an exception that isn't handled here then it will leave
// _allFilesPromise in an inconsistent state such that no additional
// done handlers will ever be called!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm reading this in the wrong context...but doesn't this try/catch handle exceptions from done handlers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't doesn't directly catch exceptions thrown from the done handlers. But it's possible for an exception handler to throw while flies up through the resolve call, which breaks that deferred. If we let it go at this point it would also break _allFilesPromise, which is what we really care about protecting, since that is what's shared.

@jasonsanjose
Copy link
Member

@iwehrman review complete

return result;
// If a done handler attached to the returned filtered files promise
// throws an exception that isn't handled here then it will leave
// _allFilesPromise in an inconsistent state such that no additional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is _allFilesPromise? This is the only reference to it I can find.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo fixed.

@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2014

I verified that this fixes the issue.

…ying to reject the promise, which probably won't work anyway.
@iwehrman
Copy link
Contributor Author

iwehrman commented Jan 8, 2014

@jasonsanjose We do currently return a new promise. That's what the return _getAllFiles().then() call does. jQuery then constructs and returns a new promise instead of just adding another handler like done. But what's CRAZY is that if the new promise created by then has a bad done handler that throws an exception, it screws up the parent promise and all subsequent promises created by then.

"bad"

@iwehrman
Copy link
Contributor Author

iwehrman commented Jan 8, 2014

Ready for re-review.

@jasonsanjose
Copy link
Member

Reviewing again. Looks like the travis error is due to github's services being down. I'll manually run the PR process locally.

@jasonsanjose
Copy link
Member

Ah thanks @iwehrman. I see now what you mean about the p3 state being messed up. Merging.

jasonsanjose added a commit that referenced this pull request Jan 8, 2014
Handle exceptions thrown in done handles attached to ProjectManager.getAllFiles
@jasonsanjose jasonsanjose merged commit 43aed7b into master Jan 8, 2014
@jasonsanjose jasonsanjose deleted the iwehrman/issue-6401 branch January 8, 2014 23:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants