Repro
#:package System.CommandLine@2.0.8
using System.CommandLine;
// This stack trace won't print to the console
Func<ParseResult, int> throwException = parseResult =>
{
throw new OperationCanceledException();
// Also doesn't work:
// throw new TaskCanceledException();
};
// This works as expected.
// Func<ParseResult, int> 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.
Repro
dotnet run Repro.csExpected 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.