{"record":{"id":"fcf0e4ac9d574d1a","repo":"DIYgod/RSSHub","slug":"unknown-time-time","errorCode":null,"errorMessage":"Unknown time: ${time}","messagePattern":"Unknown time: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/notefolio/search.tsx","lineNumber":208,"sourceCode":"        switch (time) {\n            case 'one-day':\n                startTime = dayjs().subtract(1, 'd').format('YYYY-MM-DDTHH:mm:ss.SSS');\n                break;\n\n            case 'week':\n                startTime = dayjs().subtract(7, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');\n                break;\n\n            case 'month':\n                startTime = dayjs().subtract(30, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');\n                break;\n\n            case 'three-month':\n                startTime = dayjs().subtract(90, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');\n                break;\n\n            default:\n                throw new Error(`Unknown time: ${time}`);\n        }\n        searchUrl += `&publishedAt=${startTime}Z&publishedAt=${endTime}Z`;\n    }\n\n    // 发送 HTTP GET 请求到 API 并解构返回的数据对象\n    const { data } = await got(searchUrl, {\n        headers: {\n            Origin: 'https://notefolio.net',\n        },\n    });\n\n    // 从 API 响应中提取相关数据\n    const items =\n        data?.resultData.map((item) => {\n            const { id, title, user, createdAt, categories = [], contents = [] } = item;\n\n            const description = contents.map((item) => renderContentItem(item)).join(' ');\n","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/notefolio/search.tsx#L190-L226","documentation":"A defensive default branch in the Notefolio search time-range switch, thrown when the 'time' parameter is not one of the handled cases. In practice this branch is effectively unreachable: the enclosing `if` on line 185 only enters the switch when time is in ['one-day','week','month','three-month'], all of which are cased. It exists as a safety net against a future regression where the guard and the switch drift apart.","triggerScenarios":"Only reachable if a code edit removes or alters the `time !== 'all' && [...].includes(time)` guard on line 185 while leaving the switch, allowing an arbitrary 'time' string to reach the default. With the current code, no user-supplied value can reach this throw.","commonSituations":"A maintainer refactors the time validation (e.g. switches to a lookup table) and forgets to keep the guard in sync, letting an unsupported time value through; a copy-paste of this switch into another route without the guard.","solutions":["If you genuinely see this error, the line-185 guard has been removed/broken — restore it so only allowed time values enter the switch.","Alternatively, replace the guard+switch with a single record/map lookup so validation and dispatch cannot diverge.","Add the new time option to BOTH the route parameter options (lines 125-131) and the switch cases when extending."],"exampleFix":"// before: guard on line 185 then switch with default throw\nif (time !== 'all' && ['one-day', 'week', 'month', 'three-month'].includes(time)) {\n    switch (time) {\n        // ... cases ...\n        default:\n            throw new Error(`Unknown time: ${time}`);\n    }\n}\n\n// after: single source of truth, no divergent guard\nconst timeDeltas = { 'one-day': 1, week: 7, month: 30, 'three-month': 90 } as const;\nconst delta = timeDeltas[time as keyof typeof timeDeltas];\nif (delta !== undefined) {\n    const startTime = dayjs().subtract(delta, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');\n    searchUrl += `&publishedAt=${startTime}Z&publishedAt=${endTime}Z`;\n}","handlingStrategy":"validation","validationCode":"const ALLOWED_TIMES = ['all', 'one-day', 'week', 'month', 'three-month'] as const;\ntype TimeParam = (typeof ALLOWED_TIMES)[number];\nfunction isTimeParam(v: string): v is TimeParam {\n    return (ALLOWED_TIMES as readonly string[]).includes(v);\n}\nif (!isTimeParam(time)) {\n    throw new InvalidParameterError(`Unknown time: ${time}`);\n}","typeGuard":"const isKnownTime = (t: string): t is 'one-day' | 'week' | 'month' | 'three-month' =>\n    ['one-day', 'week', 'month', 'three-month'].includes(t);","tryCatchPattern":null,"preventionTips":["Keep validation and dispatch in one structure (map/record) so they cannot drift.","Add a unit test asserting every documented time option is handled by the switch.","When adding a new time option, update the route parameter options, the guard, and the switch together."],"tags":["dead-code","defensive","validation","unreachable"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}