{"record":{"id":"b85de8611b3113b1","repo":"jackwener/OpenCLI","slug":"commandname-prompt-cannot-be-empty","errorCode":null,"errorMessage":"${commandName} prompt cannot be empty","messagePattern":"(.+?) prompt cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":162,"sourceCode":"        }\n        return null;\n      };\n\n      findComposer.toString = () => 'findComposer';\n    `;\n}\n\nexport function normalizeBooleanFlag(value, fallback = false) {\n    if (typeof value === 'boolean') return value;\n    if (value == null || value === '') return fallback;\n    const normalized = String(value).trim().toLowerCase();\n    return normalized === 'true' || normalized === '1' || normalized === 'yes' || normalized === 'on';\n}\n\nexport function requireNonEmptyPrompt(prompt, commandName) {\n    const text = String(prompt ?? '').trim();\n    if (!text) {\n        throw new ArgumentError(\n            `${commandName} prompt cannot be empty`,\n            `Example: opencli ${commandName} \"hello\"`,\n        );\n    }\n    return text;\n}\n\nexport function requirePositiveInt(value, flagLabel, hint) {\n    if (!Number.isInteger(value) || value < 1) {\n        throw new ArgumentError(`${flagLabel} must be a positive integer`, hint);\n    }\n    return value;\n}\n\nexport function requireNonNegativeInt(value, flagLabel, hint) {\n    if (!Number.isInteger(value) || value < 0) {\n        throw new ArgumentError(`${flagLabel} must be a non-negative integer`, hint);\n    }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L144-L180","documentation":"requireNonEmptyPrompt normalizes the prompt argument with String(prompt ?? '').trim() and throws ArgumentError when nothing remains. This is a guard so chatgpt commands never send an empty prompt to the page. The commandName is interpolated so the message names the specific subcommand that failed.","triggerScenarios":"Calling a chatgpt command (e.g. opencli chatgpt prompt) with no positional argument, with an empty string, or with a value that is only whitespace; also with null/undefined prompt.","commonSituations":"Scripting with shell variables that expand to empty (unset OPENAI_PROMPT var), quoting mistakes so the arg is swallowed by the shell, or piping empty stdin.","solutions":["Pass a non-empty prompt string as the positional argument, e.g. opencli chatgpt prompt \"hello\"","Check the variable you interpolate actually has content before invoking (echo it)","Quote the prompt so the shell does not drop it","Handle the ArgumentError in your wrapper and print the usage hint it carries"],"exampleFix":"// before\nopencli chatgpt prompt $MSG   // MSG unset -> empty prompt\n// after\nopencli chatgpt prompt \"${MSG:-hello}\"","handlingStrategy":"validation","validationCode":"const text = String(prompt ?? '').trim();\nif (!text) throw new Error('prompt is required');","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try { await prompt(text); } catch (e) { if (e instanceof ArgumentError) { console.error(e.message, e.hint); process.exitCode = 2; } else throw e; }","preventionTips":["Always pass a quoted positional prompt","Validate interpolated shell variables before invoking","Use \"${VAR:-default}\" to guard unset vars"],"tags":["argument-validation","cli-input","empty-string"],"backgroundTag":"empty-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}