fix: unsilence all error returns from SQL Exec, Bot API calls, and migrations
This commit is contained in:
@@ -341,7 +341,7 @@ func (h *Handler) sendExportDirect(ctx context.Context, chatID int64, user *db.U
|
||||
|
||||
// exportCallback opens the export month picker.
|
||||
func (h *Handler) exportCallback(ctx context.Context, chatID int64, msgID int, callbackID string) {
|
||||
defer h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
|
||||
defer h.answerCb(ctx, callbackID)
|
||||
user, err := h.getOrCreateUser(chatID)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -399,9 +399,9 @@ func (h *Handler) editExportMonthPicker(ctx context.Context, chatID int64, msgID
|
||||
|
||||
kb := models.InlineKeyboardMarkup{InlineKeyboard: kbRows}
|
||||
if msgID == 0 {
|
||||
h.Bot.SendMessage(ctx, &bot.SendMessageParams{ChatID: chatID, Text: "Select month to export:", ReplyMarkup: &kb})
|
||||
h.sendWithKB(ctx, chatID, "Select month to export:", kb)
|
||||
} else {
|
||||
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{ChatID: chatID, MessageID: msgID, Text: "Select month to export:", ReplyMarkup: &kb})
|
||||
h.editText(ctx, chatID, msgID, "Select month to export:", &kb)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,9 +411,7 @@ func (h *Handler) editExportYearPicker(ctx context.Context, chatID int64, msgID
|
||||
backData := fmt.Sprintf("exp_years_back_%d", refY)
|
||||
navSuffix := fmt.Sprintf("_%d", refY)
|
||||
kb := buildYearPicker("exp_", backData, navSuffix, centerYear)
|
||||
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: chatID, MessageID: msgID, Text: "Select year:", ReplyMarkup: &kb,
|
||||
})
|
||||
h.editText(ctx, chatID, msgID, "Select year:", &kb)
|
||||
}
|
||||
|
||||
// formatMonthTitle returns the localized month name and year for a given calendar.
|
||||
@@ -430,7 +428,7 @@ func formatMonthTitle(cal string, year, month int) string {
|
||||
|
||||
// handleExportCallback routes export inline button presses (year nav, month select).
|
||||
func (h *Handler) handleExportCallback(ctx context.Context, chatID int64, msgID int, callbackID, data string) {
|
||||
defer h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
|
||||
defer h.answerCb(ctx, callbackID)
|
||||
user, err := h.getOrCreateUser(chatID)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -474,18 +472,12 @@ func (h *Handler) handleExportCallback(ctx context.Context, chatID int64, msgID
|
||||
if n, _ := fmt.Sscanf(data, "exp_do_%d_%d", &y, &m); n == 2 {
|
||||
last, err := h.DB.GetLastEvent(user.ID)
|
||||
if err == nil && last != nil && last.EventType == "in" {
|
||||
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: chatID,
|
||||
MessageID: msgID,
|
||||
Text: "You are currently clocked in. Please clock out first, then try again.",
|
||||
ReplyMarkup: &models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{
|
||||
{Text: "Back to Menu", CallbackData: "back_menu"},
|
||||
},
|
||||
},
|
||||
kb := models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{{Text: "Back to Menu", CallbackData: "back_menu"}},
|
||||
},
|
||||
})
|
||||
}
|
||||
h.editText(ctx, chatID, msgID, "You are currently clocked in. Please clock out first, then try again.", &kb)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -505,34 +497,22 @@ func (h *Handler) handleExportCallback(ctx context.Context, chatID int64, msgID
|
||||
data, err := GenerateMonthlyReport(h.DB, user.ID, user.Timezone, user.ExportAccent, user.Calendar, y, m, start, end)
|
||||
if err != nil {
|
||||
slog.Error("generate report", "error", err)
|
||||
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: chatID,
|
||||
MessageID: msgID,
|
||||
Text: "Error generating report",
|
||||
ReplyMarkup: &models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{
|
||||
{Text: "Back to Menu", CallbackData: "back_menu"},
|
||||
},
|
||||
},
|
||||
kb := models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{{Text: "Back to Menu", CallbackData: "back_menu"}},
|
||||
},
|
||||
})
|
||||
}
|
||||
h.editText(ctx, chatID, msgID, "Error generating report", &kb)
|
||||
return
|
||||
}
|
||||
|
||||
slog.Info("report generated", "bytes", len(data))
|
||||
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: chatID,
|
||||
MessageID: msgID,
|
||||
Text: "Report ready:",
|
||||
ReplyMarkup: &models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{
|
||||
{Text: "Back to Menu", CallbackData: "back_menu"},
|
||||
},
|
||||
},
|
||||
kb := models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{{Text: "Back to Menu", CallbackData: "back_menu"}},
|
||||
},
|
||||
})
|
||||
}
|
||||
h.editText(ctx, chatID, msgID, "Report ready:", &kb)
|
||||
|
||||
if _, err := h.Bot.SendDocument(ctx, &bot.SendDocumentParams{
|
||||
ChatID: chatID,
|
||||
|
||||
Reference in New Issue
Block a user