DIYgod/RSSHub · warning · Error

Data source ID not found

Error message

Data source ID not found

What it means

Thrown by the NEA (National Energy Administration) bureau route when the HTML element 'ul#showData0' either doesn't exist or has no 'data' attribute, or the data attribute doesn't contain a colon-separated value with an ID at the end. The route parses this data attribute (e.g., 'something:12345') to construct a JSON data source URL (ds_12345.json).

Source

Thrown at lib/routes/gov/nea/bureau.ts:65

    ],
    name: '司工作进展',
    maintainers: ['nczitzk', 'pseudoyu'],
    handler,
    url: 'www.nea.gov.cn/',
};

async function handler(ctx) {
    const { bureau } = ctx.req.param();
    const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 35;

    const rootUrl = 'https://www.nea.gov.cn';
    const link = `${rootUrl}/sjzz/${bureau}/index.htm`;
    const response = await ofetch(link);
    const $ = load(response);

    const dataSourceId: string | undefined = $('ul#showData0').attr('data')?.split(/:/).pop();
    if (!dataSourceId) {
        throw new Error('Data source ID not found');
    }

    const jsonUrl = new URL(`ds_${dataSourceId}.json`, link).href;
    const jsonData: NeaResponse = await ofetch(jsonUrl);

    const list: DataItem[] = jsonData.datasource.slice(0, limit).map((item) => {
        const title = sanitizeHtml(item.title, { allowedTags: [], allowedAttributes: {} });

        return {
            title,
            link: new URL(item.publishUrl, rootUrl).href,
            pubDate: item.publishTime ? timezone(parseDate(item.publishTime), 8) : undefined,
            description: item.summary?.trim() || title,
            author: [...new Set([item.sourceText, item.author, item.editor, item.responsibleEditor].filter(Boolean))].map((author) => ({
                name: author!,
            })),
            category: item.keywords.split(/,/),
        };

View on GitHub (pinned to bed535e087)

Solutions

  1. Open https://www.nea.gov.cn/sjzz/{bureau}/index.htm in a browser and inspect ul#showData0 to verify the data attribute still exists
  2. If the data source mechanism changed, reverse-engineer the new data-loading approach (check network requests in DevTools)
  3. Update the selector or data-attribute parsing logic to match the new page structure
  4. Verify the bureau code is valid using the options listed in the route parameters

Example fix

// before
const dataSourceId: string | undefined = $('ul#showData0').attr('data')?.split(/:/).pop();
if (!dataSourceId) {
    throw new Error('Data source ID not found');
}

// after (more defensive parsing with diagnostic)
const dataAttr = $('ul#showData0').attr('data');
const dataSourceId = dataAttr?.split(/:/).pop();
if (!dataSourceId) {
    throw new Error(`Data source ID not found on ${link}. The page structure may have changed. ul#showData0 data attribute: ${dataAttr}`);
}
Defensive patterns

Strategy: try-catch

Try / catch

// Wrap data-source extraction in try-catch with a meaningful fallback
let dataSourceId: string | undefined;
try {
    dataSourceId = $('ul#showData0').attr('data')?.split(/:/).pop();
} catch {
    // selector or attribute missing
}
if (!dataSourceId) {
    // Fall back to parsing the page differently, or return allowEmpty
    return { title: $('title').text(), link, item: [], allowEmpty: true };
}

Prevention

When it happens

Trigger: A GET to https://www.nea.gov.cn/sjzz/{bureau}/index.htm returns HTML where ul#showData0 is missing, has no data attribute, or the data attribute format changed. The split(/:/).pop() returns undefined when the data attribute is empty or contains no colon.

Common situations: The NEA website was redesigned and the data-loading mechanism changed (e.g., switched from JSON data sources to server-side rendering); the specific bureau page uses a different HTML structure; the bureau code is valid but the page is a redirect or error page.

Related errors


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