From affa03b60fb082c93b1efa9341ac85a106dda61e Mon Sep 17 00:00:00 2001 From: James Varah <31836482+jvarah@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:09:26 +0000 Subject: [PATCH] fix(cli): report an invalid catalog --type as a usage error (#7678) `catalog --type widget` exited 1 with a runtime_error. A bad flag value is a usage mistake, so it now throws CliUsageError: exit 2, and under --json a usage_error envelope with the same message. Closes #7669 Claude-Session: https://claude.ai/code/session_01M3Xbw44WYGyVqg4AjkzFxj Co-authored-by: Claude --- packages/cli/src/cli.agentMode.test.ts | 1 + packages/cli/src/commands/catalog.ts | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/cli.agentMode.test.ts b/packages/cli/src/cli.agentMode.test.ts index 38a18073e1..2e293528aa 100644 --- a/packages/cli/src/cli.agentMode.test.ts +++ b/packages/cli/src/cli.agentMode.test.ts @@ -234,6 +234,7 @@ describe("agent-mode contract", () => { ["compare a.html b.html --timeout abc", "--timeout must be a positive integer"], ["compare a.html b.html --timeout -1", "--timeout must be a positive integer"], ["grade-compare --for frame.png", "Exactly one of --grades or --luts"], + ["catalog --type widget", 'Invalid --type: "widget". Use "block" or "component".'], ["check --range 5,1", "Invalid --range"], ["check --samples ten", "Invalid --samples"], ["check --tolerance=-1", "Invalid --tolerance"], diff --git a/packages/cli/src/commands/catalog.ts b/packages/cli/src/commands/catalog.ts index 127f968167..e871a1e4c8 100644 --- a/packages/cli/src/commands/catalog.ts +++ b/packages/cli/src/commands/catalog.ts @@ -17,7 +17,7 @@ import { loadAllItems } from "../registry/resolver.js"; import { readRegistryManifest } from "../registry/remote.js"; import { loadProjectConfig, DEFAULT_PROJECT_CONFIG } from "../utils/projectConfig.js"; import { relative, resolve } from "node:path"; -import { finishCommand } from "../utils/commandResult.js"; +import { CliUsageError, finishCommand } from "../utils/commandResult.js"; import { isUnattended } from "../utils/attendedTerminal.js"; import { runAdd } from "./add.js"; import { hasNoSearchableTokens, searchByWords } from "../registry/localSearch.js"; @@ -226,8 +226,7 @@ export default defineCommand({ if (args.type === "block") typeFilter = "hyperframes:block"; else if (args.type === "component") typeFilter = "hyperframes:component"; else if (args.type) { - console.error(`Invalid --type: "${args.type}". Use "block" or "component".`); - finishCommand(1); + throw new CliUsageError(`Invalid --type: "${args.type}". Use "block" or "component".`); } // Asked for the whole manifest on purpose: its item list defines coverage,