DIYgod/RSSHub · warning · Error

Unknown time: ${time}

Error message

Unknown time: ${time}

What it means

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.

Source

Thrown at lib/routes/notefolio/search.tsx:208

        switch (time) {
            case 'one-day':
                startTime = dayjs().subtract(1, 'd').format('YYYY-MM-DDTHH:mm:ss.SSS');
                break;

            case 'week':
                startTime = dayjs().subtract(7, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');
                break;

            case 'month':
                startTime = dayjs().subtract(30, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');
                break;

            case 'three-month':
                startTime = dayjs().subtract(90, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');
                break;

            default:
                throw new Error(`Unknown time: ${time}`);
        }
        searchUrl += `&publishedAt=${startTime}Z&publishedAt=${endTime}Z`;
    }

    // 发送 HTTP GET 请求到 API 并解构返回的数据对象
    const { data } = await got(searchUrl, {
        headers: {
            Origin: 'https://notefolio.net',
        },
    });

    // 从 API 响应中提取相关数据
    const items =
        data?.resultData.map((item) => {
            const { id, title, user, createdAt, categories = [], contents = [] } = item;

            const description = contents.map((item) => renderContentItem(item)).join(' ');

View on GitHub (pinned to bed535e087)

Solutions

  1. If you genuinely see this error, the line-185 guard has been removed/broken — restore it so only allowed time values enter the switch.
  2. Alternatively, replace the guard+switch with a single record/map lookup so validation and dispatch cannot diverge.
  3. Add the new time option to BOTH the route parameter options (lines 125-131) and the switch cases when extending.

Example fix

// before: guard on line 185 then switch with default throw
if (time !== 'all' && ['one-day', 'week', 'month', 'three-month'].includes(time)) {
    switch (time) {
        // ... cases ...
        default:
            throw new Error(`Unknown time: ${time}`);
    }
}

// after: single source of truth, no divergent guard
const timeDeltas = { 'one-day': 1, week: 7, month: 30, 'three-month': 90 } as const;
const delta = timeDeltas[time as keyof typeof timeDeltas];
if (delta !== undefined) {
    const startTime = dayjs().subtract(delta, 'd').startOf('d').format('YYYY-MM-DDTHH:mm:ss.SSS');
    searchUrl += `&publishedAt=${startTime}Z&publishedAt=${endTime}Z`;
}
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED_TIMES = ['all', 'one-day', 'week', 'month', 'three-month'] as const;
type TimeParam = (typeof ALLOWED_TIMES)[number];
function isTimeParam(v: string): v is TimeParam {
    return (ALLOWED_TIMES as readonly string[]).includes(v);
}
if (!isTimeParam(time)) {
    throw new InvalidParameterError(`Unknown time: ${time}`);
}

Type guard

const isKnownTime = (t: string): t is 'one-day' | 'week' | 'month' | 'three-month' =>
    ['one-day', 'week', 'month', 'three-month'].includes(t);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/fcf0e4ac9d574d1a. Report an issue: GitHub.