{"record":{"id":"6f89f4864699ccf7","repo":"balderdashy/sails","slug":"e-invalid-action-identity","errorCode":"E_INVALID_ACTION_IDENTITY","errorMessage":"Could not register action with invalid identity `' + identity + '`","messagePattern":"Could not register action with invalid identity `' \\+ identity \\+ '`","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/app/private/controller/help-register-action.js","lineNumber":45,"sourceCode":" *         @property {Error} origError  [the original (raw/underlying) error from `machine-as-action`]\n */\n\nmodule.exports = function helpRegisterAction(sails, action, identity, force) {\n\n  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({","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/app/private/controller/help-register-action.js#L27-L63","documentation":"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.","triggerScenarios":"Calling `sails.registerAction(fn, 'bad identity!')` with spaces, uppercase-lowercasing artifacts producing invalid names, leading slashes/dots, or empty string.","commonSituations":"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.","solutions":["Use an identity matching ^[a-z_$][a-z0-9-_.\\$]*(\\/[a-z_$][a-z0-9-_\\$.]*)*$ e.g. 'user/create' or 'admin.users.find'.","Lowercase and sanitize (replace invalid chars with dashes/underscores) before registering.","Ensure segments don't start with a digit, dot, or dash.","If deriving from filenames, strip extensions and normalize separators to '/'. "],"exampleFix":"// before\nsails.registerAction(handler, 'Users/do Stuff!');\n// after\nsails.registerAction(handler, 'users/do-stuff');","handlingStrategy":"validation","validationCode":"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); }","typeGuard":"function isValidActionIdentity(id) { return typeof id === 'string' && /^[a-z_$][a-z0-9-_.\\$]*(\\/[a-z_$][a-z0-9-_\\$.]*)*$/.test(id.toLowerCase()); }","tryCatchPattern":"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; }","preventionTips":["Use lowercase letters, numbers, dashes, underscores, dots and '/' segments in identities.","Never include spaces or symbols when generating identities from paths.","Lowercase identities before registering (registerAction lowercases internally).","Unit-test any code that programmatically builds identities."],"tags":["sails","actions","identity","validation"],"backgroundTag":"invalid-action-identity","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}