-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
passing an invalid reducer to combineReducers() silently fails #1398
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
Comments
yes, I think the combineReducer just checks if the object's provided value is a function or not, and doesn't warn if the the function passed is undefined. if (typeof reducers[key] === 'function') {
finalReducers[key] = reducers[key];
} When pushing the value to we could have something like if (typeof reducers[key] === 'function') {
finalReducers[key] = reducers[key];
} else {
throw 'The reducer' + reducers[key] + 'is not a valid type of reducer'
} |
The reason we have this check is that it used to be a popular pattern to Maybe we should give up on this behavior since we don’t encourage |
Also I might add that a reducer that throws also does so silently. You only see that its supposed to be reduced state is missing in the state. I had a wrong import for action types and my switch statement then basically said:
A I should be able to make a PR fixing the error reporting. |
Is there any news for this ? I see that it's silently failed because in createStore.js (line 170), we just skip the error. Can we catch the error and log to the console, it helps easier to debug when something wrong... |
Agree with @gaearon on this one but maybe in the next major release since this will be a breaking change for a lot of production apps using |
@Huanzhang89 Until there's a stable workaround for that case, we're not able to implement it in the library. That should continue to work, as it's a perfectly valid use case and should be expected to work. |
@timdorr Okay, thanks for the clarification Tim |
If I pass something to
combineReducers()
that doesn't really return a valid reducer, it silently fails. But if it's the only reducer passed tocombineReducers()
, it throws an error saying valid reducers were not passed. I'm not sure if it's a bug, but sure does look like one to me.Isn't it better if it warned me if one of the arguments passed to
combineReducers()
wasn't a valid reducer?I ran into this issue when I forgot to do
export default myReducer
in one of my reducer files.The text was updated successfully, but these errors were encountered: