jackwener/OpenCLI · error · ArgumentError
unknown mode "${mode}"
Error message
unknown mode "${mode}" What it means
The kimi templates command accepts a --mode flag that must be one of a fixed set (ppt, docs, deep-research, agent, websites, sheets, agent-swarm, code). If a mode string is provided but is not a key in modeMap, the command throws ArgumentError('mode', `unknown mode "${mode}"`).
Source
Thrown at clis/kimi/audit-extras.js:158
{ name: 'mode', required: false, help: 'Navigate to mode first: ppt|docs|deep-research|agent|websites|sheets|agent-swarm|code' },
{ name: 'limit', type: 'int', required: false, default: 30 },
],
columns: AUDIT_EXTRA_COLUMNS,
func: async (page, kwargs) => {
const mode = String(kwargs?.mode || '').trim().toLowerCase();
const modeMap = {
ppt: '/slides',
docs: '/docs',
'deep-research': '/deep-research',
agent: '/agent',
websites: '/websites',
sheets: '/sheets',
'agent-swarm': '/agent-swarm',
code: '/code',
};
if (mode) {
const target = modeMap[mode];
if (!target) throw new ArgumentError('mode', `unknown mode "${mode}"`);
await page.goto(`${KIMI_URL}${target.slice(1)}`);
await page.wait(2);
} else {
await ensureOnKimi(page);
}
// Templates: visible <a> or [role=button] whose text follows the
// pattern "category\n\ntitle" (e.g., "商业财经\n\n宁德时代财报分析").
const cards = await page.evaluate(`(() => {
${IS_VISIBLE_JS}
const els = Array.from(document.querySelectorAll('a, [role="button"], button')).filter(isVisible);
const out = [];
for (const el of els) {
const tx = (el.innerText || '').trim();
// Match "category\\n\\ntitle" or "category\\ntitle" patterns
const m = tx.match(/^([^\\n]+)\\n+(.+)$/);
if (m && m[1].length < 30 && m[2].length < 100 && m[1] !== m[2]) {
out.push({ category: m[1].trim(), title: m[2].trim() });
}View on GitHub (pinned to 49907e53dc)
Solutions
- Use one of the exact supported modes: ppt|docs|deep-research|agent|websites|sheets|agent-swarm|code
- Run `kimi templates --help` (or read the command args) to see the current mode list
- Omit --mode entirely to list templates on the currently open page instead of navigating
- Check for typos/aliases: 'slides' is not a mode — the mode is 'ppt'
Example fix
// before
await runCli('kimi templates', { mode: 'slides' });
// after
await runCli('kimi templates', { mode: 'ppt' }); // or omit mode
Defensive patterns
Strategy: validation
Validate before calling
const VALID_MODES = ['ppt','docs','deep-research','agent','websites','sheets','agent-swarm','code'];
if (mode && !VALID_MODES.includes(String(mode).trim().toLowerCase())) throw new Error(`mode must be one of: ${VALID_MODES.join(', ')}`); Type guard
function isValidMode(m) { return ['ppt','docs','deep-research','agent','websites','sheets','agent-swarm','code'].includes(String(m).trim().toLowerCase()); } Try / catch
try {
await runCli('kimi templates', { mode });
} catch (e) {
if (e.name === 'ArgumentError' && /unknown mode/.test(e.message)) console.error(`Bad --mode '${mode}'. Use: ppt|docs|deep-research|agent|websites|sheets|agent-swarm|code`);
else throw e;
} Prevention
- Validate --mode against the documented list before invoking
- Remember 'slides' is not valid — the mode is 'ppt'
- Check --help for newly added modes when upgrading the CLI
- Omit --mode when you want the currently open page scanned
When it happens
Trigger: Running `kimi templates --mode slide` or `--mode PPT-` or any typo/unsupported value; passing an alias not in the map (e.g. 'presentation' instead of 'ppt'); uppercase input is lowercased first, so case is not the issue — the spelling must match exactly.
Common situations: Guessing mode names from the product UI instead of the help text; using 'chat' or 'search' which are not template-bearing pages; scripts built against an older CLI whose mode list lacked newer entries like 'code' or 'agent-swarm'.
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
- coingecko limit must be a positive integer
- Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(
- INVALID_ARGUMENT
- Unknown tag: ${value}
- Unknown category: ${value}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9072351bedada2dd.
Report an issue: GitHub.