Skip to content

Commit d10549b

Browse files
xesrevinuGit Agent
andcommitted
fix(cli): handle CLI errors gracefully
- Added CLI error handling for showing help messages. - Updated error messages to reference the correct config path. This commit improves the error handling in the CLI to ensure users get Co-Authored-By: Git Agent <noreply@git-agent.dev>
1 parent 3c1094e commit d10549b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/cli.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import { NodeRuntime, NodeServices } from "@effect/platform-node";
33
import { ConfigProvider, Effect, Layer } from "effect";
4-
import { Command } from "effect/unstable/cli";
4+
import { CliError, Command } from "effect/unstable/cli";
55
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
66
import PackageJson from "../package.json" with { type: "json" };
77
import { commandRoot } from "./commands/root";
@@ -23,6 +23,11 @@ const program = Command.run(commandRoot, {
2323
Effect.provide(Live),
2424
Effect.catch((error) =>
2525
Effect.sync(() => {
26+
if (CliError.isCliError(error) && error._tag === "ShowHelp") {
27+
process.exitCode = error.errors.length > 0 ? 1 : 0;
28+
return;
29+
}
30+
2631
console.error(renderError(error));
2732
process.exitCode =
2833
error != null &&

src/commands/init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ const runInitCommandBody = Effect.fn(function* (input) {
7272
if (!input.force) {
7373
const exists = yield* fs.exists(configPath);
7474
if (exists) {
75-
const existingPath = yield* projectConfigPath(repoRoot);
7675
return yield* new ConfigError({
77-
message: `${existingPath} already exists\nhint: use --force to reinitialize`,
76+
message: `${configPath} already exists\nhint: use --force to reinitialize`,
7877
});
7978
}
8079
}

0 commit comments

Comments
 (0)