{"record":{"id":"05a161ce66b192b7","repo":"vuejs/vuex","slug":"vuex-error-in-before-action-subscribers","errorCode":null,"errorMessage":"[vuex] error in before action subscribers: ","messagePattern":"\\[vuex\\] error in before action subscribers: ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/store.js","lineNumber":161,"sourceCode":"    } = unifyObjectStyle(_type, _payload)\n\n    const action = { type, payload }\n    const entry = this._actions[type]\n    if (!entry) {\n      if (__DEV__) {\n        console.error(`[vuex] unknown action type: ${type}`)\n      }\n      return\n    }\n\n    try {\n      this._actionSubscribers\n        .slice() // shallow copy to prevent iterator invalidation if subscriber synchronously calls unsubscribe\n        .filter(sub => sub.before)\n        .forEach(sub => sub.before(action, this.state))\n    } catch (e) {\n      if (__DEV__) {\n        console.warn(`[vuex] error in before action subscribers: `)\n        console.error(e)\n      }\n    }\n\n    const result = entry.length > 1\n      ? Promise.all(entry.map(handler => handler(payload)))\n      : entry[0](payload)\n\n    return new Promise((resolve, reject) => {\n      result.then(res => {\n        try {\n          this._actionSubscribers\n            .filter(sub => sub.after)\n            .forEach(sub => sub.after(action, this.state))\n        } catch (e) {\n          if (__DEV__) {\n            console.warn(`[vuex] error in after action subscribers: `)\n            console.error(e)","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/vuejs/vuex/blob/bd907467b8392d6671bb115738285ff7f63d0cf6/src/store.js#L143-L179","documentation":"A before action subscriber (registered via subscribeAction with a before handler or object form) threw synchronously during dispatch. Vuex catches it so dispatch continues, logging a warning plus the original error in development.","triggerScenarios":"subscribeAction({ before(action, state) { ... } }) where the handler throws — e.g. accessing a property of undefined state, calling a removed API, or a logging/analytics subscriber with a bug.","commonSituations":"Analytics/log plugins written for an older Vuex signature (payload/order changed); plugin reading state fields removed after refactor; subscriber calling store methods re-entrantly.","solutions":["Wrap subscriber bodies in their own try/catch and log context","Fix the throwing logic shown by the accompanying console.error(e)","Check subscriber argument order (action, state) matches current Vuex version","Isolate subscribers by removing them one at a time to find the culprit plugin"],"exampleFix":"// before\nstore.subscribeAction({ before(action, state) { log(action.payload.detail) } })\n// after\nstore.subscribeAction({ before(action, state) { try { log(action.payload?.detail) } catch (err) { console.warn('subscriber failed', err) } } })","handlingStrategy":"try-catch","validationCode":"function safeSubscriber(fn) {\n  return (...args) => { try { return fn(...args) } catch (e) { console.warn('action subscriber error', e) } }\n}\nstore.subscribeAction({ before: safeSubscriber((action, state) => { /* ... */ }) })","typeGuard":"function isActionSubscriber(sub) {\n  return typeof sub === 'function' || (sub && ['before','after','error'].some(k => typeof sub[k] === 'function'))\n}","tryCatchPattern":"store.subscribeAction({\n  before(action, state) {\n    try { analytics.track(action.type, action.payload) }\n    catch (e) { console.warn('[vuex] before subscriber failed', e) }\n  }\n})","preventionTips":["Wrap every third-party/analytic subscriber body in try/catch","Keep subscriber signatures current with your Vuex major version","Test subscribers with representative actions including undefined payloads","Avoid re-entrant store calls (commit/dispatch) inside before subscribers"],"tags":["vuex","plugin","action-subscriber","uncaught-exception"],"backgroundTag":"plugin-subscriber-crash","analyzedSha":"bd907467b8392d6671bb115738285ff7f63d0cf6","analyzedAt":"2026-08-28T21:38:57.320Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}