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 <noreply@anthropic.com>
This commit is contained in:
James Varah
2026-11-14 00:09:26 +00:00
committed by GitHub
co-authored by Claude
parent 0f6ed7d57b
commit affa03b60f
2 changed files with 3 additions and 3 deletions
+1
View File
@@ -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"],
+2 -3
View File
@@ -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,