Skip to content

Commit

Permalink
chore: update command exception display
Browse files Browse the repository at this point in the history
fixes #2805
  • Loading branch information
yufeih committed Nov 29, 2023
1 parent eccf1d7 commit 23f8cbe
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/docfx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ internal static int Main(string[] args)
{
config.SetApplicationName("docfx");
config.UseStrictParsing();
config.SetExceptionHandler(e =>
{
if (e is CommandAppException cae && cae.Pretty is { } pretty)
AnsiConsole.Write(pretty);
else
AnsiConsole.WriteException(e, ExceptionFormats.ShortenEverything);
});
config.SetExceptionHandler(OnException);
config.AddCommand<InitCommand>("init");
config.AddCommand<BuildCommand>("build");
Expand All @@ -40,5 +34,29 @@ internal static int Main(string[] args)
});

return app.Run(args);

static void OnException(Exception e)
{
if (e is CommandAppException cae)
{
if (cae.Pretty is { } pretty)
AnsiConsole.Write(pretty);
else
AnsiConsole.MarkupInterpolated($"[red]Error:[/] {e.Message}");
}
else
{
AnsiConsole.WriteException(e, new ExceptionSettings()
{
Format = ExceptionFormats.ShortenEverything,
Style = new()
{
ParameterName = Color.Grey,
ParameterType = Color.Grey78,
LineNumber = Color.Grey78,
},
});
}
}
}
}

0 comments on commit 23f8cbe

Please sign in to comment.