dotnet / dotnet/command-line-api
System.CommandLine silently swallows OperationCanceledException and TaskCanceledException
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
### Repro
```cs
#:package System.CommandLine@2.0.8
using System.CommandLine;
// This stack trace won't print to the console
Func throwException = parseResult =>
{
throw new OperationCanceledException();
// Also doesn't work:
// throw new TaskCanceledException();
};
// This works as expected.
// Func throwException = parseResult => { throw new Exception(); };
var root = new RootCommand();
root.SetAction(throwException);
var parseResult = root.Parse(args);
return parseResult.Invoke();
// still returns exit code 1
```
`dotnet run Repro.cs`
### Expected behavior
I see the stack trace for the `OperationCanceledException`.
### Actual behavior
There is no output.
### Additional details
As a developer trying to debug why my application crashed with no output, this behavior is frustrating.
If I wanted to exit gracefully (e.g. if the user pressed Ctrl-C), then I would expect to have to catch an exception at some point, instead of System.CommandLine swallowing it for me.
Contributor guide
Assessment
This issue has not been assessed yet.