jackwener/OpenCLI · error · ArgumentError

--output 只接受 md 或 text,收到:${format}

Error message

--output 只接受 md 或 text,收到:${format}

What it means

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.

Source

Thrown at clis/mubu/notes.js:204

      name: 'from',
      help: '范围起始日,格式 YYYY-MM-DD。须与 --to 同时使用。',
    },
    {
      name: 'to',
      help: '范围截止日,格式 YYYY-MM-DD。须与 --from 同时使用。',
    },
    {
      name: 'output',
      default: 'md',
      help: '输出格式:md(默认,Markdown)或 text(纯文本)',
    },
  ],
  columns: ['date', 'content'],
  func: async (page, kwargs) => {
    const isList = kwargs.list;
    const format = kwargs.output;
    if (format !== 'md' && format !== 'text') {
      throw new ArgumentError(`--output 只接受 md 或 text,收到:${format}`);
    }

    await page.goto('https://mubu.com/app');

    const { start, end } = resolveRange(kwargs);
    const startKey = dateToKey(start);
    const endKey = dateToKey(end);

    // 并行加载所有涉及年份的 day 节点,按范围过滤
    const yearResults = await Promise.all(
      yearsInRange(start, end).map((year) => loadYearEntries(page, year)),
    );
    const allEntries = yearResults
      .flat()
      .filter((e) => e.dateKey >= startKey && e.dateKey <= endKey);

    if (allEntries.length === 0) {
      const label = startKey === endKey ? startKey : `${startKey} ~ ${endKey}`;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use --output md or --output text.
  2. Fix the variable feeding the flag in your script (e.g. ensure OUTPUT_FORMAT is set).
  3. If you wanted 'markdown', it is the same as md — use 'md'.

Example fix

// before
mubu notes --output markdown
// after
mubu notes --output md
Defensive patterns

Strategy: validation

Validate before calling

const OUTPUT_FORMATS = new Set(['md', 'text']);
if (!OUTPUT_FORMATS.has(format)) throw new Error(`--output must be md or text, got: ${format}`);

Type guard

const isOutputFormat = (f) => f === 'md' || f === 'text';

Try / catch

try {
  await notes({ output: format });
} catch (e) {
  if (e.message.includes('--output')) console.error('Use --output md or --output text');
  else throw e;
}

Prevention

When it happens

Trigger: Running the command with --output html, --output pdf, --output '' (empty), or --output passed with no value (undefined).

Common situations: Users guess at formats supported by other export tools, shell scripts pass an unset variable, or a typo like --output markdown.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/d177d2969f13d4e3. Report an issue: GitHub.