{"record":{"id":"bb1e8e034bdef2ea","repo":"santifer/career-ops","slug":"sort-must-be-date-or-score","errorCode":null,"errorMessage":"--sort must be date or score","messagePattern":"--sort must be date or score","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"company-funded.mjs","lineNumber":133,"sourceCode":"    const arg = argv[i];\n    if (arg === '--dry-run') opts.dryRun = true;\n    else if (arg === '--json') opts.json = true;\n    else if (arg === '--self-test') opts.selfTest = true;\n    else if (arg === '--help' || arg === '-h') opts.help = true;\n    else if (arg === '--limit') opts.limit = Number(argv[++i] || '');\n    else if (arg === '--months') opts.months = Number(argv[++i] || '');\n    else if (arg === '--sort') opts.sort = String(argv[++i] || '').trim().toLowerCase();\n    else if (arg === '--sources') opts.sources = parseSources(argv[++i] || '');\n    else throw new Error(`unknown option: ${arg}`);\n  }\n  if (!Number.isInteger(opts.limit) || opts.limit <= 0 || opts.limit > 100) {\n    throw new Error('--limit must be an integer from 1 to 100');\n  }\n  if (!Number.isInteger(opts.months) || opts.months <= 0 || opts.months > 120) {\n    throw new Error('--months must be an integer from 1 to 120');\n  }\n  if (!['date', 'score'].includes(opts.sort)) {\n    throw new Error('--sort must be date or score');\n  }\n  return opts;\n}\n\nfunction parseSources(value) {\n  const out = String(value || '')\n    .split(',')\n    .map((s) => normalizeSourceName(s.trim()))\n    .filter(Boolean);\n  const unique = [...new Set(out)];\n  const allowed = new Set(['techcrunch', 'prnewswire', 'guardian', 'hn']);\n  for (const source of unique) {\n    if (!allowed.has(source)) throw new Error(`unknown source in --sources: ${source}`);\n  }\n  return unique.length ? unique : [...DEFAULT_SOURCES];\n}\n\nfunction normalizeSourceName(value) {","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/company-funded.mjs#L115-L151","documentation":"CLI argument validation in company-funded.mjs's parseArgs: the --sort value, after trim/lowercase, is neither \"date\" nor \"score\". The input at fault is the token immediately after --sort; empty (missing) values also land here since the default comparison fails.","triggerScenarios":"`--sort funding` (an intuitively plausible but unsupported key), `--sort Date` would pass (lowercased) but `--sort date-desc`, `--sort relevance`, or `--sort` with a missing/empty value (`''`) all fail.","commonSituations":"Assuming more sort keys exist than the two implemented; copying a flag from another tool; wrapper scripts forwarding a user-selected sort that this script doesn't implement; version drift where a sort key was renamed.","solutions":["Use `--sort date` or `--sort score`.","Map alternative sort names to the supported keys in wrapper scripts.","Check `--help` output for the current list of accepted sort values.","If a new sort key is genuinely needed, extend the includes() check and the sort implementation."],"exampleFix":"// before\nnode company-funded.mjs --sort amount\n\n// after\nnode company-funded.mjs --sort score","handlingStrategy":"validation","validationCode":"const SORTS = new Set(['date', 'score']);\nfunction validSort(s) {\n  const v = String(s || '').trim().toLowerCase();\n  return SORTS.has(v) ? v : null;\n}","typeGuard":"const isKnownSort = (s) => ['date', 'score'].includes(String(s).trim().toLowerCase());","tryCatchPattern":"try {\n  run(['--sort', sort]);\n} catch (e) {\n  if (e.message.includes('--sort must be')) {\n    console.warn(`Unsupported sort '${sort}', falling back to 'date'`);\n    run(['--sort', 'date']);\n  } else throw e;\n}","preventionTips":["Map user-facing sort names to supported keys in wrappers.","Check --help for the current accepted set.","Normalize (trim/lowercase) user input before forwarding.","Add tests enumerating accepted enum values for CLI flags."],"tags":["cli","validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}