question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not bubble Errors from Put Effects

See original GitHub issue

I came across an issue where a reducer was expecting a property on action data that wasn’t there and so it threw an error but whenever this occurs already inside the catch statement of a saga it causes that saga, and its parents, and subsequently their children to all abort(!). This led me to question why Put effects are bubbling up errors to begin with since (it seems to me) the effect should act like an event emitter on the Redux store bus. If something throws downstream shouldn’t it be captured and logged but not bubble back into the saga?

Example:

function * watcherSaga () {
  yield * takeLatest(FOO, workerSaga)
}

function * workerSaga (action) {
  try {
    const res = yield call(xhr, {foo: action.data.foo})
    yield put(actions.fooSuccessful(res.body)
  } catch (err) {
    // uncaught thrown error here will cause the entire app to crash!
    yield put(actions.fooFailure(err)
  }
}

export default reducer ({type, data}) {
  switch (type) {
    case FOO_FAILURE:
      return state.merge({
        // this will throw and flow back into the workerSaga
        foo: data.oops.not.here
      })
    default:
      state
  }
}

I propose that the runPutEffect function handle errors much like the Cancel Effect by logging out any errors but returning the cb without the error. While the reducer should handle these error cases on its own it would still be a good defensive check to keep the entire app from cancelling.

Thoughts?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
slorbercommented, Oct 5, 2016
0reactions
yelouaficommented, Oct 14, 2016

@michaelgilley should we consider this fixed by #567?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to bubble error correctly from Promise without throw?
I am not conversant with TypeScript, but here is a javascript solution, where you use $q.reject .then(function() {}, function(error) { this.
Read more >
Error Handling | Redux-Saga
Errors in forked tasks bubble up to their parents until it is caught or reaches the root saga. If an error propagates to...
Read more >
Event Bubbling and Event Catching in JavaScript and React
In this article, I'll help you understand event bubbling and event catching like a pro. I created this resource to help you understand...
Read more >
Error handling with reactive streams. | by Kalpa Senanayake
Article walk you through various techniques available to handle errors in reactive streams. It uses Spring reactor and its fluent api to handle...
Read more >
How to properly bubble up state or global error handler
One thing we've been wondering about is if it can make sense for Reducer to return failable Effect<Action, Error> instead of the non-failing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found