{"record":{"id":"2e64645a5fe83e0f","repo":"jackwener/OpenCLI","slug":"to-from","errorCode":null,"errorMessage":"使用 --to 时必须同时指定 --from","messagePattern":"使用 --to 时必须同时指定 --from","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mubu/notes.js","lineNumber":72,"sourceCode":"  validateMonth(month);\n  return { year, month };\n}\n\nfunction dateToKey(d) {\n  return `${d.year}-${String(d.month).padStart(2, '0')}-${String(d.day).padStart(2, '0')}`;\n}\n\n/** 将各种时间参数统一解析为 {start, end} */\nfunction resolveRange(kwargs) {\n  const dateStr = kwargs.date;\n  const monthStr = kwargs.month;\n  const yearArg = kwargs.year;\n  const fromStr = kwargs.from;\n  const toStr = kwargs.to;\n\n  // --from / --to 优先级最高\n  if (fromStr || toStr) {\n    if (!fromStr) throw new ArgumentError('使用 --to 时必须同时指定 --from');\n    const start = parseDate(fromStr);\n    const end = toStr ? parseDate(toStr) : localToday();\n    if (dateToKey(start) > dateToKey(end)) throw new ArgumentError('--from 不能晚于 --to');\n    return { start, end };\n  }\n\n  if (yearArg !== undefined && yearArg !== null) {\n    validateYear(yearArg, '--year');\n    return {\n      start: { year: yearArg, month: 1, day: 1 },\n      end: { year: yearArg, month: 12, day: 31 },\n    };\n  }\n\n  if (monthStr) {\n    const { year, month } = parseMonth(monthStr);\n    return {\n      start: { year, month, day: 1 },","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/notes.js#L54-L90","documentation":"resolveRange treats --from/--to as the highest-priority range spec, but they only make sense as a pair. Supplying --to without --from is ambiguous, so it throws ArgumentError immediately.","triggerScenarios":"Running the notes command with only --to 2024-06-30, or kwargs containing { to: '2024-06-30' } with no from.","commonSituations":"Users assume --to alone means 'everything until that date'; scripts build kwargs conditionally and set to without from.","solutions":["Add the matching --from flag (e.g. --from 2024-01-01 --to 2024-06-30).","Drop --to to use the default range (or --year).","In code, only set kwargs.to when kwargs.from is also set."],"exampleFix":"// before\nawait notes({ to: '2024-06-30' });\n// after\nawait notes({ from: '2024-01-01', to: '2024-06-30' });","handlingStrategy":"validation","validationCode":"if ((kwargs.to !== undefined) !== (kwargs.from !== undefined)) {\n  throw new Error('--from and --to must be used together');\n}","typeGuard":"const hasFullRange = (k) => k.from != null && k.to != null;","tryCatchPattern":"try {\n  await notes(kwargs);\n} catch (e) {\n  if (e.message.includes('使用 --to 时必须同时指定 --from')) {\n    console.error('Provide both --from and --to together.');\n  } else throw e;\n}","preventionTips":["Treat --from/--to as an atomic pair in scripts and wrappers.","Default --from when only --to is meaningful (e.g. first day of that year).","Lint your CLI wrappers for flags that are always set together."],"tags":["argument-error","cli","flag-pairing"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}