Do not bubble Errors from Put Effects
See original GitHub issueI 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:
- Created 7 years ago
- Reactions:2
- Comments:9 (9 by maintainers)
Top GitHub Comments
@neurosnap @michaelgilley I’ve just created an issue for that: https://github.com/yelouafi/redux-saga/issues/570
@michaelgilley should we consider this fixed by #567?