feat: fallback to static AnsiConsole if exception occurs before registered in DI container

This commit is contained in:
Stevan Freeborn
2025-08-20 21:42:19 -05:00
parent 51f5359202
commit d560909f16
2 changed files with 4 additions and 4 deletions
@@ -18,9 +18,9 @@ internal static class HostBuilderExtensions
app.Configure(static c =>
c.SetExceptionHandler(static (ex, resolver) =>
{
var console = resolver?.Resolve(typeof(IAnsiConsole)) as IAnsiConsole;
console?.MarkupLine($"[red]An error occurred while executing the command:[/]");
console?.WriteException(ex, ExceptionFormats.ShortenEverything);
var console = resolver?.Resolve(typeof(IAnsiConsole)) as IAnsiConsole ?? AnsiConsole.Console;
console.MarkupLine($"[red]An error occurred while executing the command:[/]");
console.WriteException(ex, ExceptionFormats.ShortenEverything);
})
);
+1 -1
View File
@@ -25,7 +25,7 @@ try
services.AddSingleton(TimeProvider.System);
services.AddSingleton<IAudioExtractor, AudioExtractor>();
services.AddSingleton<ITranscriber, WhisperTranscriber>();
services.AddSingleton<ITranscriptAnalyzer, GeminiAnalyzer>(sp =>
services.AddSingleton<ITranscriptAnalyzer, GeminiAnalyzer>(static sp =>
{
const string modelOptionName = "Model";
const string keyOptionName = "ApiKey";