From ebe572f91c07c0de7e5c0a68c1a002d4bb3695de Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:13:39 +0700 Subject: [PATCH] Do not throw from Task.Run callback --- BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs | 2 +- BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs | 2 +- .../AI/OpenAI/OpenAIImageGenerationPromptHandler.cs | 2 ++ BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs | 2 +- BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs index 18b4320..a758939 100644 --- a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs @@ -129,7 +129,7 @@ await telegramBotClient.SendTextMessageAsync( replyToMessageId: textPrompt.Command.MessageId, cancellationToken: cancellationToken ); - throw; + return; } // Track thread diff --git a/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs index f54e5bf..7e280d6 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs @@ -105,7 +105,7 @@ await telegramBotClient.EditMessageTextAsync( parseMode: ParseMode.Html, cancellationToken: cancellationToken ); - throw; + return; } // Track thread diff --git a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs index b599153..8940cac 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs @@ -77,6 +77,8 @@ await _telegramBotClient.DeleteMessageAsync( } catch (OperationCanceledException) { // Terminate gracefully // TODO: tie up loose ends + } catch (Exception exc) { + _logger.LogError(exc, "Could not handle command"); } }); diff --git a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs index e74e851..b660df7 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs @@ -200,7 +200,7 @@ await telegramBotClient.EditMessageTextAsync( parseMode: ParseMode.Html, cancellationToken: cancellationToken ); - throw; + return; } // Track thread diff --git a/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs index 69ff246..61e6e0e 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs @@ -169,7 +169,7 @@ await telegramBotClient.EditMessageTextAsync( parseMode: ParseMode.Html, cancellationToken: cancellationToken ); - throw; + return; } // Track thread