Skip to content
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

Vuex should throw exception on missing mutation type #1638

Closed
taoeffect opened this issue Nov 5, 2019 · 1 comment

Comments

@taoeffect
Copy link
Contributor

@taoeffect taoeffect commented Nov 5, 2019

Version

3.1.1

Reproduction link

https://codesandbox.io/s/vue-template-2tpsf

Steps to reproduce

  1. Create a new vuex store
  2. From an action, commit a mutation that doesn't exist
  3. Call the action

What is expected?

For an exception to be thrown.

What is actually happening?

An exception is not thrown, instead a console.error is logged, and only if we're not running in production. If we're running in production, literally nothing happens:

    if (process.env.NODE_ENV !== 'production') {
      console.error(("[vuex] unknown mutation type: "   type));
    }

In the sandbox link above, you can see there is no exception is caught because AN ERROR WAS CAUGHT! should appear in the console log, but it doesn't, per:

      try {
        commit("fo/bar");
      } catch (e) {
        console.error("AN ERROR WAS CAUGHT!", e);
      }

Our error handling code cannot function correctly if no exception is thrown (as it should be, in this case).

@ktsn

This comment has been minimized.

Copy link
Member

@ktsn ktsn commented Nov 9, 2019

This check is meant to be notice the developers that there is a mistake on their code (which is assertion) and only available in development env. Also we strip out it on production env to reduce the file size.
You should not rely on the behavior when you implement your app logic.

@ktsn ktsn closed this Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.