{"record":{"id":"71efd8ca301d6905","repo":"jackwener/OpenCLI","slug":"indeed-sort-must-be-relevance-or-date-got","errorCode":null,"errorMessage":"indeed sort must be \"relevance\" or \"date\", got \"${value}\"","messagePattern":"indeed sort must be \"relevance\" or \"date\", got \"(.+?)\"","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/indeed/utils.js","lineNumber":86,"sourceCode":"        throw new ArgumentError(`indeed ${label} cannot be empty`);\n    }\n    return q;\n}\n\n/** \"1\" / \"3\" / \"7\" / \"14\" — accepted by Indeed's `fromage` filter. */\nexport function requireFromage(value) {\n    if (value === undefined || value === null || value === '') return '';\n    const v = String(value).trim();\n    if (!FROMAGE_VALUES.has(v)) {\n        throw new ArgumentError(`indeed fromage must be one of 1/3/7/14 (days), got \"${value}\"`);\n    }\n    return v;\n}\n\nexport function requireSort(value, defaultValue = 'relevance') {\n    const v = String(value ?? defaultValue).trim().toLowerCase();\n    if (!SORT_VALUES.has(v)) {\n        throw new ArgumentError(`indeed sort must be \"relevance\" or \"date\", got \"${value}\"`);\n    }\n    return v;\n}\n\n/**\n * Build an Indeed search URL with only the user-supplied filters set.\n * Indeed treats absent params as defaults; we never pass empty strings\n * because the page will echo them back into the query and the URL\n * stays cleaner for round-tripping.\n */\nexport function buildSearchUrl({ query, location, fromage, sort, start }) {\n    const params = new URLSearchParams();\n    params.set('q', query);\n    if (location) params.set('l', location);\n    if (fromage) params.set('fromage', fromage);\n    if (sort && sort !== 'relevance') params.set('sort', sort);\n    if (start && start > 0) params.set('start', String(start));\n    return `${INDEED_ORIGIN}/jobs?${params.toString()}`;","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/indeed/utils.js#L68-L104","documentation":"requireSort validates the sort option against the allowed set {relevance, date} (case-insensitive, trimmed). Anything else raises an ArgumentError echoing the bad value. This mirrors Indeed's search sort parameter.","triggerScenarios":"`indeed sort newest`, `sort datetime`, `sort posted_date`, or localized words like 'fecha' — values not in relevance/date.","commonSituations":"Copying flag values from other job APIs (e.g. 'newest' from other boards); assuming full 'datePosted' style names work; typos like 'relevence'.","solutions":["Use sort date for newest-first or sort relevance (the default).","Omit the flag to get the default relevance ordering.","Check spelling/case — it is lowercased before the check, so only the word itself matters."],"exampleFix":"// before\nindeed sort newest\n// after\nindeed sort date","handlingStrategy":"validation","validationCode":"const ALLOWED = new Set(['1','3','7','14']); if (fromage != null && fromage !== '' && !ALLOWED.has(String(fromage).trim())) fromage = '14';","typeGuard":"function isFromage(v) { return v == null || v === '' || ['1','3','7','14'].includes(String(v).trim()); }","tryCatchPattern":"try { run(['search', '--fromage', fromage]); } catch (e) { if (e instanceof ArgumentError && e.message.includes('fromage')) { console.warn(`Unsupported fromage \"${fromage}\"; omitting filter`); return run(['search']); } throw e; }","preventionTips":["Restrict UIs/configs to a dropdown of 1/3/7/14.","Map arbitrary day ranges to the nearest supported value.","Never append time units to the value."],"tags":["cli","enum-validation","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}