try to help debug null/undef'd Redux action errors #6178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This change introduces a new Redux middleware which checks the
action
and, if it'snull
orundefined
, throws anError
suggesting that this might be due to an invalid state transition.Reason for Changes
Our current convention for Redux state transitions in GUI involves calls of the form
dispatch(createTransitionAction(state))
. ThecreateTransitionAction
function is expected to check thestate
to determine whether the transition is allowed, and if not, the function returnsundefined
.Unfortunately, the high-level expression of this is difficult for a newcomer to interpret. The output looks similar to this:
This error happens inside of
redux-throttle
because of the way it inspects the action to do its job. With different middleware this error might be expressed differently. Redux itself would probably detect the error and provide more meaningful debugging information, but that would only happen if the empty action made it through all middleware.After this change, the output looks more like this:
In both cases, the stack trace for the exception includes the offending
dispatch
call, which should help find the failing transition function.Test Coverage
Tested locally by causing invalid state transitions. Without those, GUI works as expected.