balderdashy/sails · error

E_INVALID_ACTION_IDENTITY

E_INVALID_ACTION_IDENTITY

Error message

Could not register action with invalid identity `' + identity + '`

What it means

sails.registerAction() (help-register-action) validates action identities against a strict regex: only letters, numbers, dots, dashes, dollar signs, underscores, and slash-separated segments. An identity failing this pattern (or starting with an invalid character) throws E_INVALID_ACTION_IDENTITY.

Source

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

 *         @property {Error} origError  [the original (raw/underlying) error from `machine-as-action`]
 */

module.exports = function helpRegisterAction(sails, action, identity, force) {

  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({

View on GitHub (pinned to 7b76422cc2)

Solutions

  1. Use an identity matching ^[a-z_$][a-z0-9-_.\$]*(\/[a-z_$][a-z0-9-_\$.]*)*$ e.g. 'user/create' or 'admin.users.find'.
  2. Lowercase and sanitize (replace invalid chars with dashes/underscores) before registering.
  3. Ensure segments don't start with a digit, dot, or dash.
  4. If deriving from filenames, strip extensions and normalize separators to '/'.

Example fix

// before
sails.registerAction(handler, 'Users/do Stuff!');
// after
sails.registerAction(handler, 'users/do-stuff');
Defensive patterns

Strategy: validation

Validate before calling

var RX = /^[a-z_$][a-z0-9-_.\$]*(\/[a-z_$][a-z0-9-_\$.]*)*$/; if (!RX.test(String(identity).toLowerCase())) { throw new Error('invalid action identity: ' + identity); }

Type guard

function isValidActionIdentity(id) { return typeof id === 'string' && /^[a-z_$][a-z0-9-_.\$]*(\/[a-z_$][a-z0-9-_\$.]*)*$/.test(id.toLowerCase()); }

Try / catch

try { sails.registerAction(fn, identity); } catch (e) { if (e.code === 'E_INVALID_ACTION_IDENTITY') { sails.log.error('Fix identity: ' + e.message); throw e; } throw e; }

Prevention

When it happens

Trigger: Calling `sails.registerAction(fn, 'bad identity!')` with spaces, uppercase-lowercasing artifacts producing invalid names, leading slashes/dots, or empty string.

Common situations: Programmatically generating identities from file paths or route keys containing special characters; registering actions with names containing spaces or starting with a digit; passing user-controlled strings as identities.

Related errors


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