jackwener/OpenCLI · warning · ArgumentError
--output 只接受 md 或 text,收到:${format}
Error message
--output 只接受 md 或 text,收到:${format} What it means
The mubu document export command in clis/mubu/doc.js validates the --output flag before driving the browser. Only 'md' (Markdown) and 'text' (plain text) are supported; any other value throws an ArgumentError with a Chinese message meaning '--output only accepts md or text, received: <format>'.
Source
Thrown at clis/mubu/doc.js:22
cli({
site: 'mubu',
name: 'doc',
access: 'read',
description: '读取幕布文档内容(默认输出 Markdown,可用 --output text 输出纯文本)',
domain: 'mubu.com',
strategy: Strategy.COOKIE,
defaultFormat: 'plain',
args: [
{ name: 'id', positional: true, required: true, help: '文档 ID' },
{ name: 'output', default: 'md', help: '输出格式:md(默认,缩进列表 Markdown,适合导入 Obsidian)或 text(纯文本,适合终端阅读)' },
],
columns: ['content'],
func: async (page, kwargs) => {
const docId = kwargs.id;
const format = kwargs.output;
if (format !== 'md' && format !== 'text') {
throw new ArgumentError(`--output 只接受 md 或 text,收到:${format}`);
}
await page.goto('https://mubu.com/app');
const data = await mubuPost(page, '/document/edit/get', { docId });
let nodes = [];
try {
const def = JSON.parse(data.definition);
nodes = def.nodes ?? [];
} catch {
return [{ content: data.name }];
}
const output = format === 'md' ? nodesToMarkdown(nodes) : nodesToText(nodes);
return [{ content: output }];
},View on GitHub (pinned to 49907e53dc)
Solutions
- Use --output md to export the document as Markdown.
- Use --output text to export as plain text.
- Check spelling and case: only lowercase 'md' and 'text' are accepted.
- If another format is needed, export as md and convert locally (e.g. pandoc md -> html/pdf).
Example fix
// before mubu doc get --id 123456 --output markdown // after mubu doc get --id 123456 --output md
Defensive patterns
Strategy: validation
Validate before calling
function assertOutputFormat(fmt) {
const allowed = new Set(['md', 'text']);
if (!allowed.has(fmt)) throw new Error(`--output must be 'md' or 'text', got: ${fmt}`);
return fmt;
}
// call before invoking: assertOutputFormat(kwargs.output) Type guard
function isSupportedOutputFormat(v) {
return v === 'md' || v === 'text';
} Try / catch
try {
await exportDoc({ id, output: fmt });
} catch (e) {
if (/只接受 md 或 text/.test(e.message)) {
console.error("Unsupported --output value; use 'md' or 'text'");
process.exitCode = 2;
} else { throw e; }
} Prevention
- Only pass the exact lowercase literals 'md' or 'text' to --output.
- Normalize user input with .toLowerCase().trim() and reject anything else early.
- Do not assume PDF/HTML export exists — convert from md locally with pandoc.
- Validate flags in scripts before invoking the CLI to fail fast.
When it happens
Trigger: Passing --output with any value other than exactly 'md' or 'text' — e.g. --output markdown, --output html, --output pdf, --output MD (case-sensitive exact match), or an undefined/null value reaching the check.
Common situations: Typing long-form format names ('markdown' instead of 'md'); assuming PDF/HTML export is supported when it is not; uppercase values like 'MD' failing the exact string comparison; scripts built against a different CLI version that accepted more formats.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
- --from and --to must differ; both resolved to ${fromStation.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e42e52f11d96e86b.
Report an issue: GitHub.