{"record":{"id":"763f8eb2d71b3493","repo":"balderdashy/sails","slug":"e-conflict","errorCode":"E_CONFLICT","errorMessage":"The action `' + identity + '` could not be registered because it conflicts with a previously-registered action.","messagePattern":"The action `' \\+ identity \\+ '` could not be registered because it conflicts with a previously-registered action\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/app/private/controller/help-register-action.js","lineNumber":50,"sourceCode":"  assert(_.isObject(sails) && _.isObject(sails._actions), new Error('Consistency violation: `sails` (a Sails app instance) should be passed in as the first argument.'));\n  assert(_.isFunction(action) || _.isObject(action), new Error('Consistency violation: `action` (2nd arg) should be provided as either a req/res/next function or a machine def (actions2), but instead, got: '+util.inspect(action,{depth:null})));\n  assert(_.isString(identity), new Error('Consistency violation: Identity should be provided as a string, but instead, got: '+util.inspect(identity,{depth:null})));\n\n  // Get a reference to the Sails private actions hash.\n  var actions = sails._actions;\n\n  // Make sure identity is lowercased.\n  identity = identity.toLowerCase();\n\n  // Identities should only have letters, numbers, dots, dashes and slashes.\n  var IS_VALID_ACTION_IDENTITY_RX = /^[a-z_\\$][a-z0-9-_.\\$]*(\\/[a-z_\\$][a-z0-9-_\\$.]*)*$/;\n  if (!identity.match(IS_VALID_ACTION_IDENTITY_RX)) {\n    throw flaverr({ name: 'userError', code: 'E_INVALID_ACTION_IDENTITY' }, new Error('Could not register action with invalid identity `' + identity + '`'));\n  }\n\n  // If we already registered an action with this identity, bail unless `force` is true.\n  if (actions[identity] && !force) {\n    throw flaverr({ name: 'userError', code: 'E_CONFLICT', identity: identity}, new Error('The action `' + identity + '` could not be registered because it conflicts with a previously-registered action.'));\n  }\n\n  // If the action is already a function, hope it's a req/res function\n  // and save it in our set of actions.\n  if (_.isFunction(action)) {\n    actions[identity] = action;\n\n  }\n  // Otherwise try to interpret it as an actions2 definition and build a Callable:\n  else {\n\n    try {\n      actions[identity] = machineAsAction(_.extend({\n        implementationSniffingTactic: sails.config.implementationSniffingTactic||undefined,\n      }, action));\n    }\n    catch (e) {\n      throw flaverr({ name: 'userError', code: 'E_INVALID', identity: identity, origError: e}, new Error('The action `' + identity + '` could not be registered.  It looks like a machine definition (actions2), but it could not be used to build an action.\\nDetails: '+e.stack));","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/app/private/controller/help-register-action.js#L32-L68","documentation":"Sails keeps a registry of actions keyed by identity. registerAction() throws E_CONFLICT if an action with the same identity is already registered and the `force` option is not true, preventing silent overwriting of an action.","triggerScenarios":"Calling `sails.registerAction(fn, 'user/create')` twice, or registering an action whose identity collides with one loaded from api/controllers; re-registering during a hook reload without force.","commonSituations":"Custom hooks registering actions at lift that collide with auto-loaded controller actions; running lift code twice in tests; duplicate handlers registered under the same identity.","solutions":["Pass `{ force: true }` as the options to intentionally overwrite: `sails.registerAction(fn, identity, { force: true })`.","Rename the new action's identity to something unique.","Check `sails.getAction(identity)` before registering to detect collisions.","Guard registration code so it runs only once per process (e.g. idempotent hook initialize)."],"exampleFix":"// before\nsails.registerAction(myFn, 'user/create'); // throws if already registered\n// after\nsails.registerAction(myFn, 'user/create', { force: true });","handlingStrategy":"try-catch","validationCode":"if (sails.getAction(identity)) { sails.registerAction(fn, identity, { force: true }); } else { sails.registerAction(fn, identity); }","typeGuard":null,"tryCatchPattern":"try { sails.registerAction(fn, identity); } catch (e) { if (e.code === 'E_CONFLICT') { sails.registerAction(fn, identity, { force: true }); } else { throw e; } }","preventionTips":["Call sails.getAction(identity) before registering.","Make hook initialization idempotent so registration runs once.","Give programmatic registrations unique, namespaced identities.","Use { force: true } explicitly when overwrite is intended."],"tags":["sails","actions","conflict","registration"],"backgroundTag":"action-identity-conflict","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}