redux-logic
redux-logic copied to clipboard
Errors thrown inside transform hooks are swallowed
Errors getting thrown inside logic handlers are swallowed and the only indication you get is the generic warnTimeout
. I'm not sure of the intended behaviour here but it seems problematic to me that errors like the following are not easily visible.
createLogic({
type: 'FOO',
transform({ getState }) {
// This should fail and show up in the logs immediately
invariant(getState().someVal === true, 'This should show up in the logs')
},
})
Do you have any suggestions on how this can be handled currently or how we can update the package so that these kinds of errors aren't lost? We count on a lot of assertions like these throughout our logic to verify the state of our application. It makes debugging significantly easier if we have specific errors being logged instead of the generic timeouts.
I just wanted to add a bit more detail here. I think this is only happening inside transform callbacks. Throwing inside a process callback produces a clearer error in the logs and it happens immediately without the timeout wait.
As a workaround I've taken a similar approach to the global warnTimeout
setting @jeffbski suggested in another thread.
const createLogic = (options) => {
if (!options.warnTimeout && options.warnTimeout !== 0) {
options.warnTimeout = DEFAULT_WARN_TIMEOUT
}
if (options.transform) {
const { transform: originalTransform } = options
options.transform = (...args) => {
try {
originalTransform(...args)
} catch(error) {
// Catch here and immediately log there error
// The result is an immediate error with a useful stack trace
console.error(error)
// Throw it again so Redux Logic continues to operate as before
throw error
}
}
}
return createReduxLogic(options)
}
Thanks for clarifying. Will look into this.