DIYgod/RSSHub · warning

Nanjing, Cannot find page

Error message

Nanjing, Cannot find page

What it means

Thrown by the Nanjing government route helper (deprecated) when the category does not match any switch case. The switch default only logs 'URL pattern not matched' and leaves url as ''; a subsequent `if (url === '')` guard then throws 'Nanjing, Cannot find page'. Valid cases are news, department, district, livelihood.

Source

Thrown at lib/routes-deprecated/gov/city/nanjing/index.js:27

    switch (category) {
        case 'news':
            url = `${homePage}/njxx/`;
            break;
        case 'department':
            url = `${homePage}/bmdt/`;
            break;
        case 'district':
            url = `${homePage}/gqdt/`;
            break;
        case 'livelihood':
            url = `${homePage}/mszx/`;
            break;
        default:
            logger.error('URL pattern not matched');
    }

    if (url === '') {
        throw new Error('Nanjing, Cannot find page');
    }

    const responseData = await getContent(url, TOTAL_PAGE);
    return responseData;
};

View on GitHub (pinned to bed535e087)

Solutions

  1. Pass one of: news, department, district, livelihood.
  2. Check the calling route's namespace/parameters to confirm which category values it forwards to this helper.
  3. If you need a new category, add a switch case with the correct homePage path segment instead of bypassing the check.

Example fix

// before
url = `${homePage}/unknown/`;  // no matching case
// after
case 'news': url = `${homePage}/njxx/`; break;
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ['news', 'department', 'district', 'livelihood'];
if (!VALID.includes(category)) throw new Error(`Invalid Nanjing category. Valid: ${VALID.join(', ')}`);

Type guard

const isNanjingCategory = (v: string): v is 'news' | 'department' | 'district' | 'livelihood' =>
  ['news', 'department', 'district', 'livelihood'].includes(v);

Try / catch

try { await getContent(homePage, category); }
catch (e) { if (/Cannot find page/.test(e.message)) return fallbackFeed(); else throw e; }

Prevention

When it happens

Trigger: Calling the helper with a category string outside {news, department, district, livelihood}. The default branch leaves url empty and the post-switch check throws.

Common situations: Caller passes a slug valid for another city's route, or an upstream route forwards an unsupported category. The two-stage (log then throw) design can mask the real cause in logs.

Related errors


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