Skip to content

Commit

Permalink
fix(entrypoint): replace try catch with UseExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoopereira committed Feb 14, 2023
1 parent d8e2ffd commit 7718584
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.CommandLine.Builder;
using System.CommandLine.Parsing;
using System.IO.Abstractions;
using System.Reflection;
using dotnet.test.rerun;
using dotnet.test.rerun.Logging;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -18,21 +19,21 @@
var Log = serviceProvider.GetRequiredService<ILogger>();
var cmd = serviceProvider.GetService<RerunCommand>();

try
{
return await new CommandLineBuilder(cmd)
.UseDefaults()
.Build()
.InvokeAsync(args);
}
catch (RerunException e)
{
Log.Error(e.Message);
Log.Debug(e.StackTrace ?? string.Empty);
}
catch (Exception e)
{
Log.Exception(e);
}

return -1;
return await new CommandLineBuilder(cmd)
.UseDefaults()
.UseExceptionHandler((exception, context) =>
{
if (exception is RerunException
|| (exception is TargetInvocationException
&& exception.InnerException is RerunException))
{
Log.Error(exception.Message);
Log.Debug(exception.StackTrace ?? string.Empty);
}
else
{
Log.Exception(exception);
}
})
.Build()
.InvokeAsync(args);

0 comments on commit 7718584

Please # to comment.