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)

Most upvoted comments

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 to onSubmitFail. At the very least, it should probably be passed to a separate function (like onSubmitError) 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 error to submitError and let it get pushed into the onSubmitFail in user space. Happy to do a PR if we like that.

      try {
        result = submit(values, dispatch, props);
      } catch (submitError) {
        var error = submitError instanceof _SubmissionError2.default ? submitError.errors : submitError;

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 sets submitSucceeded to true. I needed to manually rethrow a SubmissionError with something inside the errors property 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.