{"record":{"id":"d177d2969f13d4e3","repo":"jackwener/OpenCLI","slug":"output-md-text-format-d177d2","errorCode":null,"errorMessage":"--output 只接受 md 或 text，收到：${format}","messagePattern":"--output 只接受 md 或 text，收到：(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/mubu/notes.js","lineNumber":204,"sourceCode":"      name: 'from',\n      help: '范围起始日，格式 YYYY-MM-DD。须与 --to 同时使用。',\n    },\n    {\n      name: 'to',\n      help: '范围截止日，格式 YYYY-MM-DD。须与 --from 同时使用。',\n    },\n    {\n      name: 'output',\n      default: 'md',\n      help: '输出格式：md（默认，Markdown）或 text（纯文本）',\n    },\n  ],\n  columns: ['date', 'content'],\n  func: async (page, kwargs) => {\n    const isList = kwargs.list;\n    const format = kwargs.output;\n    if (format !== 'md' && format !== 'text') {\n      throw new ArgumentError(`--output 只接受 md 或 text，收到：${format}`);\n    }\n\n    await page.goto('https://mubu.com/app');\n\n    const { start, end } = resolveRange(kwargs);\n    const startKey = dateToKey(start);\n    const endKey = dateToKey(end);\n\n    // 并行加载所有涉及年份的 day 节点，按范围过滤\n    const yearResults = await Promise.all(\n      yearsInRange(start, end).map((year) => loadYearEntries(page, year)),\n    );\n    const allEntries = yearResults\n      .flat()\n      .filter((e) => e.dateKey >= startKey && e.dateKey <= endKey);\n\n    if (allEntries.length === 0) {\n      const label = startKey === endKey ? startKey : `${startKey} ~ ${endKey}`;","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/notes.js#L186-L222","documentation":"The notes export command accepts only 'md' (Markdown) or 'text' (plain text) for the --output flag. Any other value is rejected up front with an ArgumentError before any network work happens.","triggerScenarios":"Running the command with --output html, --output pdf, --output '' (empty), or --output passed with no value (undefined).","commonSituations":"Users guess at formats supported by other export tools, shell scripts pass an unset variable, or a typo like --output markdown.","solutions":["Use --output md or --output text.","Fix the variable feeding the flag in your script (e.g. ensure OUTPUT_FORMAT is set).","If you wanted 'markdown', it is the same as md — use 'md'."],"exampleFix":"// before\nmubu notes --output markdown\n// after\nmubu notes --output md","handlingStrategy":"validation","validationCode":"const OUTPUT_FORMATS = new Set(['md', 'text']);\nif (!OUTPUT_FORMATS.has(format)) throw new Error(`--output must be md or text, got: ${format}`);","typeGuard":"const isOutputFormat = (f) => f === 'md' || f === 'text';","tryCatchPattern":"try {\n  await notes({ output: format });\n} catch (e) {\n  if (e.message.includes('--output')) console.error('Use --output md or --output text');\n  else throw e;\n}","preventionTips":["Keep the list of allowed values in one constant shared by caller and CLI.","Guard unset shell variables: : \"${OUTPUT_FORMAT:?must be md or text}\".","Map synonyms (markdown -> md) before invoking."],"tags":["argument-error","cli","flag-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}