Send bot internal error message in case of errors.#545
Send bot internal error message in case of errors.#545
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves bot-side observability by emitting “internal error” notifications to the bot chat when message handling or alert rendering fails, so operators can see bot/messaging failures directly in Discord/Telegram.
Changes:
- Fixes a typo in an alert deserialization error message.
- On pubsub message handling failures, generates and sends an
InternalErrorAlertto the bot. - Adds helper methods to send bot internal error messages to Discord/Telegram chats from
SendAlertMessageerror paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/messaging/alert.go | Corrects typo in “insufficient length” error message. |
| cmd/bots/internal/bots/messaging/pubsub_client.go | Sends an internal error alert to the bot when a pubsub message fails to parse/handle. |
| cmd/bots/internal/bots/environment.go | Adds sendErrMsg helpers and uses them to notify chats on alert rendering/sending errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| internalAlert := entities.NewInternalErrorAlert(time.Now().Unix(), hndlErr) | ||
| alertMsg, iErr := messaging.NewAlertMessageFromAlert(internalAlert) | ||
| if iErr != nil { // must never happen | ||
| logger.Error("Failed to create alert message for internal alert", attrs.Error(iErr)) | ||
| return | ||
| } | ||
| bot.SendAlertMessage(alertMsg) // send alert about something not working in the messaging service |
There was a problem hiding this comment.
In the NATS subscription handler, any parse/handle error now triggers sending an InternalErrorAlert to the bot chat. If the pubsub server publishes malformed/unexpected messages (or an attacker can publish to the subject), this can easily turn into an alert storm and drown out real alerts. Consider adding a simple rate-limit/deduplication (e.g., per error type within a time window) or restricting internal alerts to specific error classes that indicate a real service failure (vs. a single bad message).
| } | ||
|
|
||
| func (tgEnv *TelegramBotEnvironment) sendErrMsg(msg string, err error) { | ||
| errMsg := fmt.Sprintf("Bot Error - %s: %v", msg, err) |
There was a problem hiding this comment.
TelegramBotEnvironment.sendErrMsg builds a raw string and routes it through SendMessage(), which always sends with ParseMode HTML. Since error strings can contain characters like '<', '&', etc., Telegram may reject the message with an entity parsing error, defeating the purpose of notifying on failures. Consider escaping the error text for HTML (or sending error messages with ParseMode disabled / as preformatted text).
| errMsg := fmt.Sprintf("Bot Error - %s: %v", msg, err) | |
| escapedMsg := htmltmpl.HTMLEscapeString(msg) | |
| escapedErr := htmltmpl.HTMLEscapeString(fmt.Sprint(err)) | |
| errMsg := fmt.Sprintf("Bot Error - %s: %s", escapedMsg, escapedErr) |
No description provided.