Skip to content

Exception details not shown for async commands #1366

@gabrielmaldi

Description

@gabrielmaldi

When using CommandHandler.Create(MethodInfo) with an async method, if an exception is thrown, the details are not printed to the console.

class Program
{
    public void TestCommand()
    {
        throw new InvalidOperationException();
    }

    public async void TestCommandAsync()
    {
        throw new InvalidOperationException();
    }

    static int Main(string[] args)
    {
        return new CommandLineBuilder(new RootCommand()
        {
            new Command("test")
            {
                Handler = CommandHandler.Create(typeof(Program).GetMethod("TestCommand"))
            },
            new Command("test-async")
            {
                Handler = CommandHandler.Create(typeof(Program).GetMethod("TestCommandAsync"))
            }
        })
            .UseDefaults()
            .Build()
            .Invoke(args);
    }
}

This is the output generated by running both commands:

Screen Shot 2021-07-31 at 20 13 12

For the async method, only Unhandled exception is printed.

The behavior is the same if we use:

static async Task<int> Main(string[] args)
{
    return await new CommandLineBuilder(new RootCommand()
    ...
        .InvokeAsync(args);

Is there a way to get the full exception details printed to the console when using async commands?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions