Skip to content

Errors thrown reducing the RECEIVE_TYPE action using useFetcher are swallowed. #463

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

Closed
praxxis opened this issue Jan 13, 2021 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@praxxis
Copy link

praxxis commented Jan 13, 2021

React version (e.g., 16.8.5) 16/17

Concurrent mode no

Rest Hooks version (e.g., 4.5.9) 5.0.0-k.*

Describe the bug
If an error occurs while processing the RECEIVE_TYPE action type the promise returned by useFetcher is not rejected. An example of how this could occur would be an updater function that throws an error.

Interestingly it looks like there's already a question in the code on whether this bug occurs. Errors are caught, but they're returned, not thrown, by the reducer.

To Reproduce

  1. Load up https://codesandbox.io/s/modest-cache-m2frd?file=/src/App.js
  2. Click the "add" button and note that a new entry is added to the list.
  3. Uncomment the error on line 8 (// throw new Error("oh no");) and reload.
  4. Click the "add" button and note that the server request succeeds, but nothing is appended to the list, and no error is thrown.

Expected behavior
Some sort of error should be observable, ideally by having the useFetcher promise reject.

Additional context
We discovered this bug as a cross browser issue (object.fromEntities does not exist in Safari 11 and we were baffled by items not being added to our lists along with there being no errors), but were able to create a more generic reproduction that could occur with any code base.

@praxxis praxxis added the bug Something isn't working label Jan 13, 2021
@ntucker
Copy link
Collaborator

ntucker commented Jan 13, 2021

Thanks for the report and detailed description!

@ntucker
Copy link
Collaborator

ntucker commented Jan 13, 2021

The design here seems related to #458. So we can probably resolve these together.

The handling of errors on reducer that you linked to places them inside the state. (You can observe this by inspecting the state.) For declarative binds, this means the components would find the error (https://github.com/coinbase/rest-hooks/blob/master/packages/core/src/react-integration/hooks/useError.ts).

So essentially there is currently a distinction between fully processing on the promise returned from these promises. In #458 this means we didn't run all the denormalization stuff, and in this case we didn't handle errors from the reducer.

It looks like probably the best design is for the promises instead of focusing on resolving the fetch, they resolve the entire update into the store.

In this case, we would want to await the promise returned from dispatch() (which means react updated), then look for errors (to handle this issue), and also resolve if none are found to handle #458.

@praxxis thumbs up if this design seems like a good resolution

@praxxis
Copy link
Author

praxxis commented Jan 13, 2021

Sounds good to me. We've also seen the behaviour described in #458 (returning a POJO) and assumed it was by design, so I'll be following along there too.

@ntucker
Copy link
Collaborator

ntucker commented Apr 17, 2021

Tracking solution in #760

@ntucker ntucker closed this as completed Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants