jackwener/OpenCLI · error · ArgumentError
月份格式错误:${s},应为 YYYY-MM
Error message
月份格式错误:${s},应为 YYYY-MM What it means
parseMonth expects a YYYY-MM string: splitting on '-' must yield exactly two numeric parts. Anything else throws ArgumentError with the expected format.
Source
Thrown at clis/mubu/notes.js:50
}
}
function parseDate(s) {
const parts = s.split('-').map(Number);
if (parts.length !== 3 || parts.some(isNaN)) {
throw new ArgumentError(`日期格式错误:${s},应为 YYYY-MM-DD`);
}
const [year, month, day] = parts;
validateYear(year);
validateMonth(month);
validateDay(year, month, day);
return { year, month, day };
}
function parseMonth(s) {
const parts = s.split('-').map(Number);
if (parts.length !== 2 || parts.some(isNaN)) {
throw new ArgumentError(`月份格式错误:${s},应为 YYYY-MM`);
}
const [year, month] = parts;
validateYear(year);
validateMonth(month);
return { year, month };
}
function dateToKey(d) {
return `${d.year}-${String(d.month).padStart(2, '0')}-${String(d.day).padStart(2, '0')}`;
}
/** 将各种时间参数统一解析为 {start, end} */
function resolveRange(kwargs) {
const dateStr = kwargs.date;
const monthStr = kwargs.month;
const yearArg = kwargs.year;
const fromStr = kwargs.from;
const toStr = kwargs.to;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass exactly YYYY-MM, e.g. 2024-01.
- Trim a full ISO date down: s.slice(0, 7).
- Pre-validate with /^\d{4}-\d{2}$/.test(s).
Example fix
// before
parseMonth('2024-01-15');
// after
parseMonth('2024-01'); Defensive patterns
Strategy: validation
Validate before calling
const MONTH_RE = /^\d{4}-\d{2}$/;
if (!MONTH_RE.test(s)) throw new Error(`month must be YYYY-MM, got: ${s}`); Type guard
const isMonthString = (s) => typeof s === 'string' && /^\d{4}-\d{2}$/.test(s); Try / catch
try {
const m = parseMonth(input);
} catch (e) {
if (/月份格式错误/.test(e.message)) console.error('Use YYYY-MM format:', e.message);
else throw e;
} Prevention
- Slice full ISO dates (s.slice(0, 7)) when a month string is required.
- Do not pass full dates or timestamps where YYYY-MM is expected.
- Validate with a regex before invoking the parser.
When it happens
Trigger: Calling parseMonth('2024'), parseMonth('2024-1-15'), or parseMonth('Jan 2024').
Common situations: Users pass a full date where a month is expected, omit the month entirely, or scripts pass ISO timestamps like 2024-01T00:00:00Z.
Related errors
- 日期格式错误:${s},应为 YYYY-MM-DD
- 月份非法:${month},应为 1-12
- 日期非法:${year}-${month}-${day}(${year} 年 ${month} 月共 ${maxDay}
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ff9ea393997fa705.
Report an issue: GitHub.