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

Fix error handling for observer.next #910

Merged
merged 2 commits into from
Nov 15, 2016

Conversation

cannoneyed
Copy link
Contributor

@cannoneyed cannoneyed commented Nov 15, 2016

When observer.next is called in queryListenerForObserver based on the results of a given query and itself throws an error, the error handling logic surrounding it automatically casts that error into an ApolloError, even though it didn't originate within apollo-client.

This is a big problem in react-apollo (see this issue). observer.next calls the method that forces a rerender, and when child components throw an error they bubble up and wind up being handled by the catch statement in queryListenerForObserver, which turns it into an ApolloError, effectively swallowing the error.

This PR rearranges the error handling logic in order to effectively capture errors that occur within apollo-client (such as mismatches in data being read from the store) and allows errors that occur outside of apollo-client (when thrown from within observer.next) to propagate correctly.

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change
  • Add your name and email to the AUTHORS file (optional)
  • If this was a change that affects the external API, update the docs and post a link to the PR in the discussion

@apollo-cla
Copy link

@cannoneyed: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

Copy link
Contributor

@helfer helfer left a comment

Choose a reason for hiding this comment

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

@cannoneyed Thanks for this great PR! This simple change should make debugging a lot easier.

Looking at the code, it is possible that transformResult throws an error which no longer gets caught, but I think that's okay since transformResult is either user-provided, or doesn't do anything.

@helfer helfer merged commit 2ae02e7 into apollographql:master Nov 15, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
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