{"record":{"id":"0ac2ac0234146396","repo":"jackwener/OpenCLI","slug":"label-is-required","errorCode":null,"errorMessage":"${label} is required","messagePattern":"(.+?) is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/_atlassian/shared.js","lineNumber":242,"sourceCode":"}\n\nexport function queryString(params) {\n    const qs = new URLSearchParams();\n    for (const [key, value] of Object.entries(params)) {\n        if (value === undefined || value === null || value === '') continue;\n        if (Array.isArray(value)) {\n            for (const item of value) qs.append(key, String(item));\n        } else {\n            qs.set(key, String(value));\n        }\n    }\n    const s = qs.toString();\n    return s ? `?${s}` : '';\n}\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`${label} is required`);\n    return s;\n}\n\nexport function requirePayloadObject(value, label) {\n    if (!value || typeof value !== 'object' || Array.isArray(value)) {\n        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an object.`);\n    }\n    return value;\n}\n\nexport function requirePayloadArray(value, label) {\n    if (!Array.isArray(value)) {\n        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an array.`);\n    }\n    return value;\n}\n\nexport function requirePayloadString(value, field, label) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/_atlassian/shared.js#L224-L260","documentation":"requireString throws this ArgumentError when a required string argument is missing, empty, or whitespace-only after String() coercion and trimming. It is the input-validation gate for mandatory CLI parameters (page IDs, titles, space keys, issue keys, etc.).","triggerScenarios":"Calling a command without its required positional/flag argument, e.g. confluence get page with no --id, or passing --title \"\" / whitespace; also null/undefined values passed programmatically.","commonSituations":"Forgot a required flag in a script; shell variable holding the ID is empty because an earlier command failed; YAML/JSON pipeline passes null for an optional-looking field that is actually required.","solutions":["Supply the missing argument named by ${label} (e.g. --id, --title, --space).","If the value comes from a shell variable, verify it is non-empty before invoking (echo it or use ${VAR:?}).","Check the command's help output for which arguments are mandatory.","In scripts, fail fast when upstream commands produce empty output instead of forwarding it."],"exampleFix":"# before\nopencli confluence get page --id \"$PAGE_ID\"   # PAGE_ID empty\n# after\n: \"${PAGE_ID:?PAGE_ID must be set}\"\nopencli confluence get page --id \"$PAGE_ID\"","handlingStrategy":"validation","validationCode":"function requireArg(v, label) {\n  const s = String(v ?? '').trim();\n  if (!s) throw new Error(`${label} is required`);\n  return s;\n}\nconst id = requireArg(args.id, 'page id');","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  const page = await cmd({ id: args.id });\n} catch (e) {\n  if (e instanceof ArgumentError || /is required/.test(e.message)) {\n    console.error(`Usage: ${cmdName} --id <pageId>`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Validate all required CLI inputs in a preflight step before invoking commands.","Use ${VAR:?} shell guards for variables feeding required arguments.","Fail fast when upstream commands return empty output.","Keep a checked wrapper/helper for every command invocation in scripts."],"tags":["validation","arguments","cli","atlassian"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}