redux-form: handleSubmit swallows errors thrown in onSubmit functions
I was having an issue where I was getting SET_SUBMIT_FAILED on every submit, even though my form had no validation errors. The error would come back empty. After digging into handleSubmit, it turns out that the try here will catch any type of error and will only give you error messages if caught error has submitError.errors.
https://github.com/erikras/redux-form/blob/master/src/handleSubmit.js#L20
try {
result = submit(values, dispatch, props);
} catch (submitError) {
var error = submitError instanceof _SubmissionError2.default ? submitError.errors : undefined;
In my case, I had a type error in my onSubmit function that was very hard to track down. Should we just rethrow if the error is a general runtime error? Something like this:
try {
result = submit(values, dispatch, props);
} catch (submitError) {
var error = submitError instanceof _SubmissionError2.default ? submitError.errors : undefined;
if (!error) throw submitError;
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 7
- Comments: 19 (3 by maintainers)
Fix published in
v6.2.0.Might be going against the grain here, but I’d honestly expect anything outside
SubmissionError(or whatever other validation errors) to be re-thrown, rather than caught and handed toonSubmitFail. At the very least, it should probably be passed to a separate function (likeonSubmitError) if that function is defined, or re-thrown if not.Just ran into this today, took quite a bit of debugging before realizing handleSubmit was obscuring all errors.
After looking at it more, I do think the simplest, most elegant solution is to just set
errortosubmitErrorand let it get pushed into theonSubmitFailin user space. Happy to do a PR if we like that.Just ran into this. Would greatly appreciate a solution that surfaces errors thrown in onSubmit instead of failing silently!
Just ran into this. It doesn’t just swallow the error, but the call to
stopSubmit(error)actually setssubmitSucceededtotrue. I needed to manually rethrow aSubmissionErrorwith something inside theerrorsproperty to avoid this.@akhayoon If you wrap your passed function in a try/catch you can print the errors before they’re caught and swallowed.