Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(cli): handle rg exit 2 in ix text instead of dumping Node stack (#218)

josephismikhail4705e951baf1
diff --git a/ix-cli/src/cli/commands/text.ts b/ix-cli/src/cli/commands/text.ts
index 7704ce86..6a8c159f 100644
--- a/ix-cli/src/cli/commands/text.ts
+++ b/ix-cli/src/cli/commands/text.ts
@@ -66,11 +66,21 @@ export function registerTextCommand(program: Command): void {
stderr("Error: ripgrep (rg) is not installed. Install it: https://github.com/BurntSushi/ripgrep#installation");
process.exit(1);
}
+ // rg exit 1 = no matches; render as empty result set
if (err.code === 1 || err.status === 1) {
formatTextResults([], opts.format);
- } else {
- throw err;
+ return;
}
+ // rg exit 2 = usage/regex error (e.g. literal "\n" in regex,
+ // unbalanced escape). Surface rg's stderr verbatim so the caller
+ // sees the actual cause instead of a raw Node stack.
+ const rgStderr = typeof err.stderr === "string" ? err.stderr.trim() : "";
+ const firstLine = rgStderr.split("\n", 1)[0] ?? "";
+ stderr(`Error: ripgrep failed${firstLine ? `: ${firstLine}` : ""}`);
+ if (rgStderr && rgStderr !== firstLine) {
+ stderr(rgStderr);
+ }
+ process.exit(1);
}
});
}