Skip to content

Commit 1198da0

Browse files
committed
Disable System.CommandLine default exception handler
System.CommandLine 2.0.3 has a built-in exception handler that catches exceptions from action handlers and prints the full stack trace. This prevents our outer try/catch in Program.cs from ever firing. Disable it via InvocationConfiguration.EnableDefaultExceptionHandler = false so our custom error formatting (red ERROR message, no stack trace) works. https://claude.ai/code/session_012xcdjzU1pwoMLVyjrhs1Gf
1 parent 02dce3a commit 1198da0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/CommandLine/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.CommandLine;
3+
using System.CommandLine.Invocation;
34
using XRepo.CommandLine.Commands;
45
using XRepo.CommandLine.Infrastructure;
56
using XRepo.Core;
@@ -17,9 +18,14 @@
1718
rootCommand.Subcommands.Add(new WhereCommand(environment, bootstrapChecker));
1819
rootCommand.Subcommands.Add(new WhichCommand(environment, bootstrapChecker));
1920

21+
var invocationConfig = new InvocationConfiguration
22+
{
23+
EnableDefaultExceptionHandler = false
24+
};
25+
2026
try
2127
{
22-
return rootCommand.Parse(args).Invoke();
28+
return rootCommand.Parse(args).Invoke(invocationConfig);
2329
}
2430
catch (CommandFailureException ex)
2531
{

0 commit comments

Comments
 (0)