{"record":{"id":"fac0a13da8398a47","repo":"nodejs/node","slug":"second-argument-username-is-required","errorCode":null,"errorMessage":"Second argument `username` is required.","messagePattern":"Second argument `username` is required\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/org.js","lineNumber":59,"sourceCode":"          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(\n        [memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\\t')\n      )\n    } else if (!this.npm.silent) {\n      output.standard(","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/org.js#L41-L77","documentation":"Thrown by the `org set` method when the org name is present but the second argument `username` is missing or falsy. The set operation requires knowing which user to add/modify in the org, so a missing username is a fatal precondition failure.","triggerScenarios":"Running `npm org set my-org` without a username argument. The args are destructured as `[cmd, orgname, username, role]`; if username resolves to undefined after org passes its check, this error fires.","commonSituations":"Forgetting the username in the command, or passing it in the wrong positional slot. Scripting the command where the username variable resolved to empty due to a variable naming error.","solutions":["Supply the username as the second argument: `npm org set <orgname> <username> [role]`","In scripts, assert the username variable is a non-empty string before calling","Review the argument order with `npm org set --help`"],"exampleFix":"// before\nnpm org set my-org\n\n// after\nnpm org set my-org someuser","handlingStrategy":"validation","validationCode":"function validateOrgSetArgs(org, user) {\n  if (!org) throw new Error('orgname is required')\n  if (!user) throw new Error('username is required')\n}","typeGuard":"function hasUsername(user) {\n  return typeof user === 'string' && user.trim().length > 0\n}","tryCatchPattern":"try {\n  await exec(['set', orgName, userName, role])\n} catch (e) {\n  if (e.message.includes('username')) {\n    console.error('Usage: npm org set <orgname> <username> [role]')\n  }\n  throw e\n}","preventionTips":["Always include the username as the second positional argument","In scripts, assert username is non-empty before invoking npm org set","Remember the argument order: org first, then user, then role"],"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"}