DIYgod/RSSHub · warning · InvalidParameterError

Invalid category

Error message

Invalid category

What it means

Thrown by the LinkResearcher (领研) route when the category query parameter is not one of 'theses', 'information', or 'careers'. The category is extracted from a URLSearchParams string in the :params path segment (format: category=theses&subject=...). Object.hasOwn(categoryMap, category) guards the lookup.

Source

Thrown at lib/routes/linkresearcher/index.tsx:63

        name: '文章',
    },
    'zh-TW': {
        name: '文章',
    },
};

async function handler(ctx: Context): Promise<Data> {
    const categoryMap = { theses: '论文', information: '新闻', careers: '职业' } as const;
    const params = ctx.req.param('params');
    const filters = new URLSearchParams(params);

    const subject = filters.get('subject');
    const columns = filters.get('columns');
    const query = filters.get('query') ?? '';
    const category = filters.get('category') ?? ('theses' as keyof typeof categoryMap);

    if (!Object.hasOwn(categoryMap, category)) {
        throw new InvalidParameterError('Invalid category');
    }
    let title = categoryMap[category] as string;

    const token = crypto.randomUUID();

    const data: {
        filters: {
            status: boolean;
            subject?: string;
            columns?: string;
        };
    } = { filters: { status: true } };

    if (subject) {
        data.filters.subject = subject;
        title += `「${subject}」`;
    }

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only 'theses', 'information', or 'careers' as the category value.
  2. List valid categories in the error message.
  3. If the params string is malformed (missing =), URLSearchParams.get returns null and the default kicks in — so the error specifically means an explicit-but-wrong value.

Example fix

// before
if (!Object.hasOwn(categoryMap, category)) {
    throw new InvalidParameterError('Invalid category');
}

// after
const validCategories = Object.keys(categoryMap);
if (!validCategories.includes(category)) {
    throw new InvalidParameterError(`Invalid category '${category}'. Supported: ${validCategories.join(', ')}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const categoryMap = { theses: '论文', information: '新闻', careers: '职业' } as const;
const validCategories = Object.keys(categoryMap);
const category = filters.get('category') ?? 'theses';
if (!validCategories.includes(category)) {
    throw new InvalidParameterError(`Invalid category '${category}'. Supported: ${validCategories.join(', ')}`);
}

Type guard

function isLinkResearcherCategory(c: string): c is keyof typeof categoryMap {
    return c in categoryMap;
}

Prevention

When it happens

Trigger: Calling the route with category=news, category=papers, or any value outside the three allowed keys. Also fires when the params string omits category entirely — but the default 'theses' prevents that; only an explicitly invalid value triggers it.

Common situations: User guesses a category name instead of consulting the docs. A user passes 'paper' (singular) instead of 'theses'. The site adds a new category and the route map is not updated.

Related errors


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