{"record":{"id":"a4146e4fb6cf241c","repo":"jackwener/OpenCLI","slug":"label-cannot-be-empty-a4146e","errorCode":null,"errorMessage":"${label} cannot be empty","messagePattern":"(.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/twitter/archive.js","lineNumber":14,"sourceCode":"import fs from 'node:fs';\nimport path from 'node:path';\nimport { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\n\n// Safety cap only. Full-archive runs can set a higher page budget via --max-pages.\nexport const DEFAULT_MAX_PAGINATION_PAGES = 100;\nconst HARD_MAX_PAGINATION_PAGES = 100000;\n\nexport function resolveOptionalFilePath(raw, label) {\n    if (raw === undefined || raw === null || raw === '')\n        return '';\n    const value = String(raw).trim();\n    if (!value)\n        throw new ArgumentError(`${label} cannot be empty`);\n    return path.resolve(value);\n}\n\nexport function ensureParentDir(filePath) {\n    if (!filePath)\n        return;\n    fs.mkdirSync(path.dirname(filePath), { recursive: true });\n}\n\nfunction removeFile(filePath) {\n    if (!filePath)\n        return;\n    try {\n        fs.rmSync(filePath, { force: true });\n    }\n    catch {\n    }\n}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/archive.js#L1-L32","documentation":"resolveOptionalFilePath treats a provided path argument as optional: undefined/null/empty string returns ''. But if a non-empty raw value is given whose trimmed form is empty (e.g. whitespace-only), it throws ArgumentError with the parameter's label. This catches shell quoting accidents where a flag was passed but the value collapsed to whitespace.","triggerScenarios":"Passing --resume-file or --output-file with a value that is only whitespace after String(raw).trim() — e.g. --output-file \" \" or an unquoted shell variable that expands to spaces.","commonSituations":"Unset environment variables quoted in shell ($OUTPUT_FILE expanding to ''), copy-paste artifacts, or scripts building CLI args with empty variables.","solutions":["Check the value passed to --resume-file/--output-file is a real non-blank path","In shell, quote variables and guard: ${OUTPUT_FILE:?unset}","Omit the flag entirely if you do not want a file — the helper returns '' for absent values","echo the constructed command line to see what the flag actually received"],"exampleFix":"// before\nnode cli.js twitter archive --resume-file \"$RESUME_FILE\"\n// after\nnode cli.js twitter archive ${RESUME_FILE:+--resume-file \"$RESUME_FILE\"}","handlingStrategy":"validation","validationCode":"function safePathArg(v) {\n  if (v === undefined || v === null) return '';\n  const s = String(v).trim();\n  return s || null; // null signals 'flag passed but blank — fix before calling'\n}","typeGuard":"function isNonEmptyPath(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  await archiveCmd(kwargs);\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('cannot be empty')) {\n    console.error('A path flag was passed with a blank value — check shell variables');\n  } else throw err;\n}","preventionTips":["Use ${VAR:?unset} in shell to fail early on blank variables","Omit optional flags entirely instead of passing empty values","Echo the assembled command before running in scripts","Trim and validate path args at script boundaries"],"tags":["arguments","validation","cli"],"backgroundTag":"empty-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}