DIYgod/RSSHub · warning · InvalidParameterError

Invalid state '${state}'

Error message

Invalid state '${state}'

What it means

Thrown as an `InvalidParameterError` when the `state` path parameter for the People's Daily message board route is not in the `allowedStates` set. Valid states are: '1' (全部/all), '2' (待回复/pending reply), '3' (办理中/in progress), '4' (已办理/resolved). The handler defaults to '1' if no state is provided.

Source

Thrown at lib/routes/people/liuyan.ts:74

    },
    name: '领导留言板',
    maintainers: ['nczitzk', 'pseudoyu'],
    handler,
    url: 'liuyan.people.com.cn/',
    description: `| 全部 | 待回复 | 办理中 | 已办理 |
| ---- | ------ | ------ | ------ |
| 1    | 2      | 3      | 4      |`,
};

async function handler(ctx) {
    const fid = ctx.req.param('id');
    if (!/^\d+$/.test(fid)) {
        throw new InvalidParameterError(`Invalid forum id '${fid}'`);
    }

    const state = ctx.req.param('state') ?? '1';
    if (!allowedStates.has(state)) {
        throw new InvalidParameterError(`Invalid state '${state}'`);
    }

    const limit = Number(ctx.req.query('limit') ?? 30);
    const forumUrl = `${rootUrl}/threads/list?fid=${fid}`;
    const currentUrl = `${forumUrl}#state=${state}`;
    const apiResponse = await ofetch<ApiResponse>(apiUrl, {
        method: 'POST',
        responseType: 'json',
        headers: {
            Referer: forumUrl,
        },
        body: new URLSearchParams({
            fid,
            state,
            lastItem: '0',
        }),
    });

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only state values 1 (全部), 2 (待回复), 3 (办理中), or 4 (已办理).
  2. Omit the state parameter entirely to default to '1' (全部/all).
  3. Refer to the route description table in `lib/routes/people/liuyan.ts` for the state mapping.
Defensive patterns

Strategy: validation

Validate before calling

// Validate state against allowed set
const allowedStates = new Set(['1', '2', '3', '4']);
if (!allowedStates.has(state)) {
    throw new InvalidParameterError(
        `Invalid state '${state}'. Must be one of: 1 (全部), 2 (待回复), 3 (办理中), 4 (已办理)`
    );
}

Type guard

function isValidMessageState(state: string): state is '1' | '2' | '3' | '4' {
    return ['1', '2', '3', '4'].includes(state);
}

Prevention

When it happens

Trigger: Requesting `/people/liuyan/<id>/<state>` with a state value not in {1, 2, 3, 4} (e.g., '0', '5', 'all', 'pending'). The state parameter is optional and defaults to '1'.

Common situations: User passes a descriptive string instead of the numeric code. User guesses a state number outside the supported range. User passes '0' expecting it to mean 'all' (the actual 'all' value is '1').

Related errors


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