DIYgod/RSSHub · error · Error

Invalid time range: ${finalSearchParams.time_range}

Error message

Invalid time range: ${finalSearchParams.time_range}

What it means

Thrown by the Voronoi `getPostItems` helper when the `time_range` parameter, after uppercasing, is not one of the values in `TimeRangeParam.options` (`WEEK`, `MONTH`, `YEAR`, `ALL`). The validation runs `.every()` to check that no option matches — if none match, it throws. This is a generic `Error`.

Source

Thrown at lib/routes/voronoiapp/common.ts:30

    tab?: string;
    time_range?: string;
    category?: string;
    order?: string;
    author?: string;
    limit?: number;
    offset?: number;
}): Promise<DataItem[]> {
    const baseUrl = 'https://9oyi4rk426.execute-api.ca-central-1.amazonaws.com/production/post';
    const url = new URL(baseUrl);
    const finalSearchParams = {
        limit: 20,
        offset: 0,
        ...params,
    };
    if (finalSearchParams.time_range !== undefined) {
        finalSearchParams.time_range = finalSearchParams.time_range.toUpperCase();
        if (TimeRangeParam.options.every((option) => option.value !== finalSearchParams.time_range)) {
            throw new Error(`Invalid time range: ${finalSearchParams.time_range}`);
        }
        // The Voronoi API doesn't support "ALL"
        if (finalSearchParams.time_range === 'ALL') {
            finalSearchParams.time_range = undefined;
        }
    }
    if (finalSearchParams.category !== undefined && finalSearchParams.category !== null) {
        const category = finalSearchParams.category;
        finalSearchParams.category = CategoryParam.options.find((option) => option.value.toLowerCase() === category.toLowerCase())?.value;
        if (finalSearchParams.category === undefined) {
            throw new Error(`Invalid category: ${finalSearchParams.category}`);
        }
    }
    if (finalSearchParams.tab !== undefined && finalSearchParams.tab !== null) {
        finalSearchParams.tab = finalSearchParams.tab.toUpperCase();
        if (!Object.values(TabMap).includes(finalSearchParams.tab)) {
            throw new Error(`Invalid tab: ${finalSearchParams.tab}`);
        }

View on GitHub (pinned to bed535e087)

Solutions

  1. Use one of the valid time range values: `WEEK`, `MONTH`, `YEAR`, or `ALL` (case-insensitive).
  2. Omit the time_range parameter to use the default `MONTH` in the popular route.
  3. If calling `getPostItems` directly, pass `undefined` instead of an invalid string.

Example fix

// before
GET /voronoiapp/popular/most-popular/DAY
// after
GET /voronoiapp/popular/most-popular/WEEK
Defensive patterns

Strategy: validation

Validate before calling

const VALID_TIME_RANGES = ['WEEK', 'MONTH', 'YEAR', 'ALL'];
function isValidTimeRange(tr: string): boolean {
    return VALID_TIME_RANGES.includes(tr.toUpperCase());
}
// Validate before calling getPostItems
if (time_range && !isValidTimeRange(time_range)) {
    throw new InvalidParameterError(`Invalid time range: ${time_range}. Valid: ${VALID_TIME_RANGES.join(', ')}`);
}

Type guard

function isValidTimeRange(tr: string): tr is 'WEEK' | 'MONTH' | 'YEAR' | 'ALL' {
    return ['WEEK', 'MONTH', 'YEAR', 'ALL'].includes(tr.toUpperCase());
}

Prevention

When it happens

Trigger: Calling `getPostItems({ time_range: 'DAY' })` or passing any string not equal (after `.toUpperCase()`) to `WEEK`, `MONTH`, `YEAR`, or `ALL`. In the popular route, this is triggered by the third path segment: `/voronoiapp/popular/:tab/:time_range/:category`.

Common situations: User passes a custom time range like `DAY`, `HOUR`, or `TODAY` that the API doesn't support. Or passes a numeric value. The `ALL` value is special-cased: it's valid for validation but then set to `undefined` before the API call because the Voronoi API doesn't support it.

Related errors


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