DIYgod/RSSHub · warning · Error
Invalid date format. Expected YYYYMMDD, for example `2026031
Error message
Invalid date format. Expected YYYYMMDD, for example `20260316`.
What it means
Thrown by the Fjdaily (Fujian Daily) route's `getIssueDate` function when the user-supplied `date` parameter does not match the regex `/^\d{8}$/`. The route expects exactly 8 digits in YYYYMMDD format (e.g., `20260316`). This is pre-flight validation before any network request is made.
Source
Thrown at lib/routes/fjdaily/index.ts:92
const getItemDescription = (detail: CheerioAPI) => {
const mainContent = detail('#content');
const attachment = detail('.attachment');
const mainDescription = getDescription(mainContent);
const mainMediaSources = new Set(
mainContent
.find('img, video, audio, source')
.toArray()
.map((item: Element) => getNodeSrc(item))
.filter(Boolean)
);
return mergeDescription(detail, mainDescription, attachment, mainMediaSources);
};
const getIssueDate = async (date: string | undefined) => {
if (date) {
if (!/^\d{8}$/.test(date)) {
throw new Error('Invalid date format. Expected YYYYMMDD, for example `20260316`. ');
}
return {
yearMonth: date.slice(0, 6),
day: date.slice(6, 8),
};
}
const indexResponse = await got(`${ROOT_URL}/pc/col/index.html`);
const $ = load(indexResponse.data);
const latestPath = $('#list li:first-child a').attr('href');
if (!latestPath) {
throw new Error('Failed to locate the latest Fujian Daily edition.');
}
const [, yearMonth, day] = latestPath.match(/(\d{6})\/(\d{2})\/node_\d+\.html/) ?? [];
View on GitHub (pinned to bed535e087)
Solutions
- Format the date as exactly 8 digits: YYYYMMDD, e.g., `/fjdaily/20260316`.
- Remove all separators (dashes, slashes) from the date string.
- Omit the date parameter entirely to fetch the latest edition automatically.
Defensive patterns
Strategy: validation
Validate before calling
function validateDateString(date: string | undefined): { yearMonth: string; day: string } {
if (!date) throw new Error('Date is required');
if (!/^\d{8}$/.test(date)) {
throw new Error('Invalid date format. Expected YYYYMMDD, e.g., 20260316');
}
return { yearMonth: date.slice(0, 6), day: date.slice(6, 8) };
} Type guard
function isValidYYYYMMDD(date: string): boolean {
if (!/^\d{8}$/.test(date)) return false;
const year = parseInt(date.slice(0, 4));
const month = parseInt(date.slice(4, 6));
const day = parseInt(date.slice(6, 8));
return year >= 1900 && month >= 1 && month <= 12 && day >= 1 && day <= 31;
} Prevention
- Format dates as exactly 8 digits: YYYYMMDD (no separators).
- Omit the date parameter to auto-fetch the latest edition.
- Validate both format and logical date ranges (month 1-12, day 1-31).
When it happens
Trigger: A user passes a date in the wrong format: `/fjdaily/2026-03-16` (dashes), `/fjdaily/2026/03/16` (slashes), `/fjdaily/260316` (6 digits), `/fjdaily/202603160` (9 digits), or any non-numeric string. The regex test fails immediately.
Common situations: User passes a date with separators (dashes, slashes, dots). User passes a 6-digit or 10-digit date. User passes a locale-formatted date string. User passes a date that is valid as a date but wrong as a format (e.g., `March 16, 2026`).
Related errors
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Nanjing, Cannot find page
- Bad category. See <a href="https://docs.rsshub.app/routes/go
- Bad category. See <a href="https://docs.rsshub.app/routes/go
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/724cd5cb45abd75f.
Report an issue: GitHub.