dotnet / dotnet/command-line-api

`UseExceptionHandler` exit code is not honored when a custom delegate is provided

Open
#1,869 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

When both a custom `errorExitCode` value **_and_** a custom handler delegate are passed to `UseExceptionHandler`, and an exception is thrown by the handler, then the custom exit code is not honored.

```csharp
var rootCmd = new RootCommand();
rootCmd.SetHandler(_ => throw new Exception());

var parser = new CommandLineBuilder(rootCmd)
.UseExceptionHandler(
(_, _) => { },
errorExitCode: 42)
.Build();

var exitCode = parser.Invoke("");

exitCode.Should().Be(42);
// ACTUAL: 0
```

See: https://github.com/dotnet/command-line-api/issues/796#issuecomment-1273848670

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.