{"record":{"id":"b77eb88dd1325a82","repo":"jackwener/OpenCLI","slug":"missing-required-argument-name","errorCode":null,"errorMessage":"Missing required argument: ${name}","messagePattern":"Missing required argument: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mercury/utils.js","lineNumber":11,"sourceCode":"import fs from 'node:fs';\nimport path from 'node:path';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\n\nexport const MERCURY_EXPENSES_URL = 'https://app.mercury.com/expenses/my-expenses';\nexport const RECEIPT_INPUT_SELECTOR = '[data-testid=\"expense-attachment-upload\"]';\n\nexport function requireString(kwargs, name) {\n    const value = kwargs[name];\n    if (typeof value !== 'string' || value.trim() === '') {\n        throw new ArgumentError(`Missing required argument: ${name}`);\n    }\n    return value.trim();\n}\n\nexport function optionalString(kwargs, name, fallback) {\n    const value = kwargs[name];\n    if (typeof value !== 'string' || value.trim() === '') return fallback;\n    return value.trim();\n}\n\nexport function optionalBoolean(kwargs, name, fallback = false) {\n    const value = kwargs[name];\n    if (typeof value === 'boolean') return value;\n    if (typeof value === 'string') {\n        const normalized = value.trim().toLowerCase();\n        if (['1', 'true', 'yes', 'y', 'on'].includes(normalized)) return true;\n        if (['0', 'false', 'no', 'n', 'off'].includes(normalized)) return false;\n        throw new ArgumentError(`Boolean argument ${name} must be true or false`);","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mercury/utils.js#L1-L29","documentation":"requireString is the CLI's input-validation helper: it asserts that a named argument exists in the kwargs object and is a non-empty (after trim) string. If not, it throws ArgumentError with 'Missing required argument: <name>'. This is fail-fast validation so the automation never runs with incomplete reimbursement data.","triggerScenarios":"Calling normalizeReimbursementInput (or the receipt/amount/date helpers) with kwargs lacking the given key, or with a value that is not a string or is whitespace-only — e.g. omitting --receipt, passing an empty string, or passing a non-string type (number/null).","commonSituations":"CLI invocation missing a required flag; a wrapper script passes empty env vars; JSON config has the key with null or a number instead of a string; shell quoting strips the value so only an empty string arrives.","solutions":["Pass the missing argument explicitly, e.g. --receipt /path/to/receipt.pdf with a non-empty string value.","Check quoting in the shell/CI so the value is not swallowed (empty string still fails validation).","Inspect the calling code (normalizeReimbursementInput) to confirm which argument name is required and its expected format.","If a numeric argument (like amount) is intended, pass it as a string per the CLI's expected input format."],"exampleFix":"// before\nawait draftReimbursement({});\n// after\nawait draftReimbursement({ receipt: '/invoices/receipt.pdf', amount: '42.50', date: '2026-08-29', merchant: 'Acme' });","handlingStrategy":"validation","validationCode":"function assertRequiredArgs(kwargs, names) {\n    for (const n of names) {\n        if (typeof kwargs[n] !== 'string' || kwargs[n].trim() === '') {\n            throw new Error(`Missing required argument: ${n}`);\n        }\n    }\n}\nassertRequiredArgs(input, ['receipt', 'amount', 'date']);","typeGuard":"function hasString(v) { return typeof v === 'string' && v.trim() !== ''; }\nconst inputValid = (i) => hasString(i.receipt) && hasString(i.amount) && hasString(i.date);","tryCatchPattern":"try {\n    await draftReimbursement(input);\n} catch (err) {\n    if (err instanceof ArgumentError && err.message.startsWith('Missing required argument')) {\n        console.error('Usage: provide --receipt <path> --amount <n> --date <YYYY-MM-DD>');\n        process.exitCode = 2;\n        return;\n    }\n    throw err;\n}","preventionTips":["Validate the full kwargs object before invoking the CLI flow.","In shell scripts, quote all argument values and check for empty env vars.","Document required flags in --help and enforce them early.","Coerce numeric config values to strings before passing them."],"tags":["argument-validation","cli","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}