santifer/career-ops · error · Error
--sort must be date or score
Error message
--sort must be date or score
What it means
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.
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.
Example fix
// before node company-funded.mjs --sort amount // after node company-funded.mjs --sort score
Defensive patterns
Strategy: validation
Validate before calling
const SORTS = new Set(['date', 'score']);
function validSort(s) {
const v = String(s || '').trim().toLowerCase();
return SORTS.has(v) ? v : null;
} Type guard
const isKnownSort = (s) => ['date', 'score'].includes(String(s).trim().toLowerCase());
Try / catch
try {
run(['--sort', sort]);
} catch (e) {
if (e.message.includes('--sort must be')) {
console.warn(`Unsupported sort '${sort}', falling back to 'date'`);
run(['--sort', 'date']);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: `--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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- unknown source in --sources
- Application answer state must be one of
- Application Answers section has
- decision must be one of
- --from and --to must both be supplied together (or neither…
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/bb1e8e034bdef2ea.
Report an issue: GitHub.
Appendix: source
Thrown at company-funded.mjs:133
const arg = argv[i];
if (arg === '--dry-run') opts.dryRun = true;
else if (arg === '--json') opts.json = true;
else if (arg === '--self-test') opts.selfTest = true;
else if (arg === '--help' || arg === '-h') opts.help = true;
else if (arg === '--limit') opts.limit = Number(argv[++i] || '');
else if (arg === '--months') opts.months = Number(argv[++i] || '');
else if (arg === '--sort') opts.sort = String(argv[++i] || '').trim().toLowerCase();
else if (arg === '--sources') opts.sources = parseSources(argv[++i] || '');
else throw new Error(`unknown option: ${arg}`);
}
if (!Number.isInteger(opts.limit) || opts.limit <= 0 || opts.limit > 100) {
throw new Error('--limit must be an integer from 1 to 100');
}
if (!Number.isInteger(opts.months) || opts.months <= 0 || opts.months > 120) {
throw new Error('--months must be an integer from 1 to 120');
}
if (!['date', 'score'].includes(opts.sort)) {
throw new Error('--sort must be date or score');
}
return opts;
}
function parseSources(value) {
const out = String(value || '')
.split(',')
.map((s) => normalizeSourceName(s.trim()))
.filter(Boolean);
const unique = [...new Set(out)];
const allowed = new Set(['techcrunch', 'prnewswire', 'guardian', 'hn']);
for (const source of unique) {
if (!allowed.has(source)) throw new Error(`unknown source in --sources: ${source}`);
}
return unique.length ? unique : [...DEFAULT_SOURCES];
}
function normalizeSourceName(value) {View on GitHub (pinned to aac998c7ed)