{"record":{"id":"a54998802489fb66","repo":"nodejs/node","slug":"first-argument-orgname-is-required","errorCode":null,"errorMessage":"First argument `orgname` is required.","messagePattern":"First argument `orgname` is required\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/org.js","lineNumber":55,"sourceCode":"    }, opts => {\n      switch (cmd) {\n        case 'add':\n        case 'set':\n          return this.set(orgname, username, role, opts)\n        case 'rm':\n          return this.rm(orgname, username, opts)\n        case 'ls':\n          return this.ls(orgname, username, opts)\n        default:\n          throw this.usageError()\n      }\n    })\n  }\n\n  async set (org, user, role, opts) {\n    role = role || 'developer'\n    if (!org) {\n      throw new Error('First argument `orgname` is required.')\n    }\n\n    if (!user) {\n      throw new Error('Second argument `username` is required.')\n    }\n\n    if (!['owner', 'admin', 'developer'].find(x => x === role)) {\n      throw new Error(\n        'Third argument `role` must be one of `owner`, `admin`, or `developer`, with `developer` being the default value if omitted.'\n      )\n    }\n\n    const memDeets = await liborg.set(org, user, role, opts)\n    if (opts.json) {\n      output.standard(JSON.stringify(memDeets, null, 2))\n    } else if (opts.parseable) {\n      output.standard(['org', 'orgsize', 'user', 'role'].join('\\t'))\n      output.standard(","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/org.js#L37-L73","documentation":"Thrown by the `org set` method (alias `org add`) when the first positional argument `orgname` is missing or falsy. The `set` method assigns a user a role within an npm organization and requires at minimum an org name, a username, and optionally a role (defaults to 'developer'). Without an org name, the API call cannot proceed.","triggerScenarios":"Running `npm org set` (or `npm org add`) without any arguments, or with an empty/undefined first argument. The exec method destructures `[cmd, orgname, username, role]` from args, and if orgname is undefined/falsy when set/add is dispatched, this throws.","commonSituations":"Typing `npm org set` and forgetting arguments, or scripting the command without checking that the org name variable is populated. Using a script that reads org name from an environment variable that was not set.","solutions":["Provide the org name as the first argument: `npm org set <orgname> <username> [role]`","If scripting, validate that the org name variable is non-empty before invoking the command","Check `npm org --help` for correct argument order"],"exampleFix":"// before\nnpm org set someuser developer\n\n// after — orgname must come first\nnpm org set my-org someuser developer","handlingStrategy":"validation","validationCode":"function validateOrgArgs(org, user, role) {\n  if (!org) throw new Error('orgname is required')\n  if (!user) throw new Error('username is required')\n  const validRoles = ['owner', 'admin', 'developer']\n  if (role && !validRoles.includes(role)) throw new Error(`Invalid role: ${role}`)\n}","typeGuard":"function hasOrgName(org) {\n  return typeof org === 'string' && org.trim().length > 0\n}","tryCatchPattern":"try {\n  await exec(['set', orgName, userName, role])\n} catch (e) {\n  if (e.message.includes('orgname')) {\n    console.error('Usage: npm org set <orgname> <username> [role]')\n  }\n  throw e\n}","preventionTips":["Always pass arguments in the correct order: orgname, username, role","In scripts, validate that org name is a non-empty string before calling npm org set","Use npm org set --help to confirm the argument layout"],"tags":["npm","org","argument-validation","cli"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}