jackwener/OpenCLI · error · ArgumentError
weibo user-posts ${name} must use YYYY-MM-DD
Error message
weibo user-posts ${name} must use YYYY-MM-DD What it means
readDate() validates the --start/--end CLI options for the weibo user-posts command. When a date argument is present but does not match the strict YYYY-MM-DD pattern (DATE_RE), it throws this ArgumentError before any scraping happens. The library throws early so the failure is a clear input error rather than a confusing downstream empty result.
Source
Thrown at clis/weibo/user-posts.js:32
if (!value) {
throw new ArgumentError('weibo user-posts id cannot be empty');
}
return value;
}
function readLimit(raw) {
const value = raw === undefined || raw === null || raw === '' ? DEFAULT_LIMIT : Number(raw);
if (!Number.isInteger(value) || value < 1 || value > MAX_LIMIT) {
throw new ArgumentError(`weibo user-posts limit must be an integer between 1 and ${MAX_LIMIT}`);
}
return value;
}
function readDate(raw, name) {
if (raw === undefined || raw === null || raw === '') return null;
const value = String(raw).trim();
if (!DATE_RE.test(value)) {
throw new ArgumentError(`weibo user-posts ${name} must use YYYY-MM-DD`);
}
const date = new Date(`${value}T00:00:00+08:00`);
if (!Number.isFinite(date.getTime()) || value !== formatShanghaiDate(date)) {
throw new ArgumentError(`weibo user-posts ${name} must be a valid calendar date`);
}
return value;
}
function formatShanghaiDate(date) {
const parts = new Intl.DateTimeFormat('en-CA', {
timeZone: 'Asia/Shanghai',
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).formatToParts(date);
const get = (type) => parts.find((part) => part.type === type)?.value;
return `${get('year')}-${get('month')}-${get('day')}`;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Reformat the value to strict YYYY-MM-DD with zero-padded month and day (e.g. '2024-01-15').
- Check the calling script for date formatting bugs or accidental whitespace; readDate trims but the pattern still must match.
- If the value may be empty/absent, pass null/undefined instead of a placeholder like '-' so readDate returns null.
Example fix
// before node weibo user-posts --id 123456 --start 2024/03/01 --end 2024/03/31 // after node weibo user-posts --id 123456 --start 2024-03-01 --end 2024-03-31
Defensive patterns
Strategy: validation
Validate before calling
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
function isValidCliDate(v) {
return v === undefined || v === null || v === '' || (typeof v === 'string' && DATE_RE.test(v.trim()));
}
if (!isValidCliDate(start) || !isValidCliDate(end)) throw new Error('dates must be YYYY-MM-DD or empty'); Type guard
function isDateString(v) {
return typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v);
} Prevention
- Always build date strings with an ISO formatter (e.g. toISOString().slice(0,10)) rather than manual concatenation.
- Zero-pad months and days explicitly in scripts.
- Pass null/undefined (not placeholders) when a bound is absent.
- Unit-test any script that generates start/end values.
When it happens
Trigger: Passing start/end values like '2024/01/15', '01-15-2024', '2024-1-5', '20240115', or a string with whitespace/extra characters to readDate via the start or end callers.
Common situations: Users copy dates with slashes from a file manager, scripts pass epoch timestamps, shell variable interpolation produces partial dates, or locale-formatted dates (e.g. en-US 'MM/DD/YYYY') are supplied.
Related errors
- ${label} is required (YYYY-MM-DD)
- --${name} must be YYYY-MM-DD, got ${JSON.stringify(raw)}
- --${name} has invalid month/day: ${value}
- huodongxing ${label} must be a valid YYYY-MM-DD date
- Date must be YYYY-MM-DD: ${date}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0b0cfecebf1c05b9.
Report an issue: GitHub.