{"record":{"id":"fe9d0ec654fda0bd","repo":"jackwener/OpenCLI","slug":"label-cannot-be-empty","errorCode":null,"errorMessage":"${label} cannot be empty","messagePattern":"(.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/_shared/common.js","lineNumber":29,"sourceCode":"}\nexport function clampInt(raw, fallback, min, max) {\n    const parsed = Number(raw);\n    if (!Number.isFinite(parsed)) {\n        return fallback;\n    }\n    return clamp(Math.floor(parsed), min, max);\n}\nexport function normalizeNumericId(value, label, example) {\n    const normalized = String(value ?? '').trim();\n    if (!/^\\d+$/.test(normalized)) {\n        throw new ArgumentError(`${label} must be a numeric ID`, `Pass a numeric ${label}, for example: ${example}`);\n    }\n    return normalized;\n}\nexport function requireNonEmptyQuery(value, label = 'query') {\n    const normalized = String(value ?? '').trim();\n    if (!normalized) {\n        throw new ArgumentError(`${label} cannot be empty`);\n    }\n    return normalized;\n}\n","sourceCodeStart":11,"sourceCodeEnd":33,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/_shared/common.js#L11-L33","documentation":"requireNonEmptyQuery rejects empty/whitespace-only query strings. Since it trims the value first, a string of spaces is also considered empty. It throws ArgumentError '<label> cannot be empty' to stop pointless remote searches.","triggerScenarios":"Calling requireNonEmptyQuery with '' , '   ', null, or undefined — typically a --query/--jql CLI option that was not supplied or was interpolated empty from a variable.","commonSituations":"Shell variable holding the query is unset/empty ($Q expands to nothing); config file field left blank; quoting bug that drops the argument entirely; search string composed of only whitespace after sanitization.","solutions":["Pass a non-empty search/query value on the command line or in the config field.","Check the shell variable feeding the flag: `${Q:-}` unset produces an empty argument — quote and default it or fail fast.","Guard in scripts: `[ -n \"$QUERY\" ] || { echo 'query required'; exit 1; }` before invoking the CLI."],"exampleFix":"// before\ncli jira search --query \"$QUERY\"   # QUERY is empty\n// after\n[ -n \"$QUERY\" ] && cli jira search --query \"$QUERY\" || { echo 'QUERY is required'; exit 1; }","handlingStrategy":"validation","validationCode":"const q = String(value ?? '').trim();\nif (!q) throw new Error(`${label} is required and cannot be empty`);","typeGuard":"const isNonEmpty = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  const q = requireNonEmptyQuery(raw, 'query');\n} catch (err) {\n  if (err.name === 'ArgumentError' && err.message.includes('cannot be empty')) {\n    console.error('No query supplied: check the --query flag or the variable feeding it.');\n  }\n  throw err;\n}","preventionTips":["Quote shell variables (\"$QUERY\") and check they are non-empty before invoking.","Require query fields in config schemas (non-empty string).","Trim and validate interactive input before passing it on."],"tags":["validation","empty-input","argument-validation","cli"],"backgroundTag":"empty-required-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}