jackwener/OpenCLI · error · ArgumentError
月份非法:${month},应为 1-12
Error message
月份非法:${month},应为 1-12 What it means
validateMonth guards that a month is an integer in 1-12 before any date math is done. The mubu notes CLI throws ArgumentError whenever a month value fails this check, so downstream date ranges are never built from nonsense months.
Source
Thrown at clis/mubu/notes.js:24
function localToday() {
const d = new Date();
return { year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate() };
}
function lastDayOfMonth(year, month) {
return new Date(year, month, 0).getDate();
}
function validateYear(year, label = '年份') {
if (!Number.isInteger(year) || year < 1) {
throw new ArgumentError(`${label} 非法:${year},应为正整数`);
}
}
function validateMonth(month) {
if (!Number.isInteger(month) || month < 1 || month > 12) {
throw new ArgumentError(`月份非法:${month},应为 1-12`);
}
}
function validateDay(year, month, day) {
const maxDay = lastDayOfMonth(year, month);
if (!Number.isInteger(day) || day < 1 || day > maxDay) {
throw new ArgumentError(`日期非法:${year}-${month}-${day}(${year} 年 ${month} 月共 ${maxDay} 天)`);
}
}
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);View on GitHub (pinned to 49907e53dc)
Solutions
- Correct the month value to an integer 1-12.
- If the month came from new Date().getMonth(), add 1 (JS months are 0-based).
- Validate user input with a regex like /^\d{4}-\d{2}(-\d{2})?$/ before calling the parser.
Example fix
// before
await notes({ from: '2024-13-01' });
// after
await notes({ from: '2024-12-01' }); Defensive patterns
Strategy: validation
Validate before calling
function isValidMonth(m) { return Number.isInteger(m) && m >= 1 && m <= 12; }
if (!isValidMonth(month)) throw new Error(`month must be 1-12, got ${month}`); Type guard
const isValidMonth = (m) => Number.isInteger(m) && m >= 1 && m <= 12;
Try / catch
try {
const d = parseDate(input);
} catch (e) {
if (/月份非法/.test(e.message)) console.error('Fix the month (1-12):', e.message);
else throw e;
} Prevention
- Use date strings rather than raw month numbers so the parser validates everything.
- Remember JS getMonth() is 0-based — always add 1.
- Regex-validate YYYY-MM-DD input before parsing.
When it happens
Trigger: Calling parseDate('2024-13-01') or parseMonth('2024-00'), or passing month=2.5 or a string month through any code path that reaches validateMonth.
Common situations: Users type malformed --from/--to values, scripts produce 0-based months (JS getMonth()), or locales emit MM values >12 from misparsed strings.
Related errors
- 日期非法:${year}-${month}-${day}(${year} 年 ${month} 月共 ${maxDay}
- 日期格式错误:${s},应为 YYYY-MM-DD
- 月份格式错误:${s},应为 YYYY-MM
- 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/6117a016f94e72e6.
Report an issue: GitHub.