balderdashy/sails · error

E_CONFLICT

E_CONFLICT

Error message

The action `' + identity + '` could not be registered because it conflicts with a previously-registered action.

What it means

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.

Source

Thrown at lib/app/private/controller/help-register-action.js:50

  assert(_.isObject(sails) && _.isObject(sails._actions), new Error('Consistency violation: `sails` (a Sails app instance) should be passed in as the first argument.'));
  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})));
  assert(_.isString(identity), new Error('Consistency violation: Identity should be provided as a string, but instead, got: '+util.inspect(identity,{depth:null})));

  // Get a reference to the Sails private actions hash.
  var actions = sails._actions;

  // Make sure identity is lowercased.
  identity = identity.toLowerCase();

  // Identities should only have letters, numbers, dots, dashes and slashes.
  var IS_VALID_ACTION_IDENTITY_RX = /^[a-z_\$][a-z0-9-_.\$]*(\/[a-z_\$][a-z0-9-_\$.]*)*$/;
  if (!identity.match(IS_VALID_ACTION_IDENTITY_RX)) {
    throw flaverr({ name: 'userError', code: 'E_INVALID_ACTION_IDENTITY' }, new Error('Could not register action with invalid identity `' + identity + '`'));
  }

  // If we already registered an action with this identity, bail unless `force` is true.
  if (actions[identity] && !force) {
    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.'));
  }

  // If the action is already a function, hope it's a req/res function
  // and save it in our set of actions.
  if (_.isFunction(action)) {
    actions[identity] = action;

  }
  // Otherwise try to interpret it as an actions2 definition and build a Callable:
  else {

    try {
      actions[identity] = machineAsAction(_.extend({
        implementationSniffingTactic: sails.config.implementationSniffingTactic||undefined,
      }, action));
    }
    catch (e) {
      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));

View on GitHub (pinned to 7b76422cc2)

Solutions

  1. Pass `{ force: true }` as the options to intentionally overwrite: `sails.registerAction(fn, identity, { force: true })`.
  2. Rename the new action's identity to something unique.
  3. Check `sails.getAction(identity)` before registering to detect collisions.
  4. Guard registration code so it runs only once per process (e.g. idempotent hook initialize).

Example fix

// before
sails.registerAction(myFn, 'user/create'); // throws if already registered
// after
sails.registerAction(myFn, 'user/create', { force: true });
Defensive patterns

Strategy: try-catch

Validate before calling

if (sails.getAction(identity)) { sails.registerAction(fn, identity, { force: true }); } else { sails.registerAction(fn, identity); }

Try / catch

try { sails.registerAction(fn, identity); } catch (e) { if (e.code === 'E_CONFLICT') { sails.registerAction(fn, identity, { force: true }); } else { throw e; } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of balderdashy/sails@7b76422cc2 (2026-09-01). Data as JSON: /api/errors/763f8eb2d71b3493. Report an issue: GitHub.