fix(tgbot): suppress 'message not modified' log spam from refresh buttons - #6340
fix(tgbot): suppress 'message not modified' log spam from refresh buttons#6340BlindMaster24 wants to merge 1 commit into
Conversation
829d96b to
f4847b7
Compare
| // isTelegramNotModifiedError checks if the Telegram API returned a "message | ||
| // not modified" error, which happens when editMessageText or | ||
| // editMessageReplyMarkup is called with content identical to the existing message. |
There was a problem hiding this comment.
🟡 Nit — comment block exceeds the repo's 2-line maximum
This new doc comment is 3 lines. CLAUDE.md hard rule:
Comments in committed Go/TS: 2 lines MAX per comment block. Make the name carry the meaning first and rename rather than annotate; spend the 2 lines on the why a name cannot hold — an invariant, an issue number, a non-obvious constraint. Exempt:
//go:build,//go:generate, and other directives.
isTelegramNotModifiedError already carries the what, and the two call sites at L212-L217 show where it applies, so the third line is restatement. No linter catches this one — it has to be done by hand.
| // isTelegramNotModifiedError checks if the Telegram API returned a "message | |
| // not modified" error, which happens when editMessageText or | |
| // editMessageReplyMarkup is called with content identical to the existing message. | |
| // Telegram answers a no-op edit with a 400 whose description carries this text; | |
| // a refresh tap that changed nothing is not an operator-visible failure. |
| func TestIsTelegramNotModifiedError(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| err error | ||
| want bool | ||
| }{ | ||
| {"nil error", nil, false}, | ||
| {"not modified", errors.New("Bad Request: message is not modified"), true}, | ||
| {"No fields to modify", errors.New("Bad Request: No fields to modify"), true}, | ||
| {"unrelated error", errors.New("Bad Request: message to edit not found"), false}, | ||
| {"network error", errors.New("connection reset"), false}, | ||
| {"empty string", errors.New(""), false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := isTelegramNotModifiedError(tt.err) | ||
| if got != tt.want { | ||
| t.Errorf("isTelegramNotModifiedError(%v) = %v, want %v", tt.err, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 Nit — the test pins the helper, not the fix
This test calls isTelegramNotModifiedError directly with hand-built errors.New(...) strings. It never invokes editMessageCallbackTgBot or editMessageTgBot, and never asserts that a not-modified error stops reaching logger.Warning — which is the behaviour the PR title promises.
Delete just the guard at L212-L218 or L232-L238 and leave the helper in place: Go allows an unused package-level function, so this test stays green while the log spam is fully back. CLAUDE.md:
A test must fail without its fix. Write it, revert the fix, watch it go red, restore.
The pieces to pin it are already in the package: bot is built with telego.WithAPIServer(...) (tgbot.go:430), so an httptest.Server returning Telegram's message is not modified body can back it, and logger.GetLogs(c int, level string) (logger.go:220) can assert no Warning-level entry was recorded. That version goes red when either guard is removed; this one does not.
No suggestion block — this is a new test, not an edit to this one.
Code reviewNo blocking issues — Reviewed head: Both nits are posted inline:
Coverage
|
… calls When users click Refresh buttons in the Telegram bot (usage_refresh, client_refresh, ips_refresh, onlines_refresh), editMessageText and editMessageReplyMarkup are always called even when the content has not changed. Telegram returns a 400 "message is not modified" error which was logged as Warning, cluttering the logs on every refresh click. Add isTelegramNotModifiedError helper that detects this specific Telegram API error and logs it at Debug level instead of Warning.
f4847b7 to
5ab9042
Compare
|
@claude done! |
Summary
Suppress noisy "message is not modified" warnings in Telegram bot edit calls when users click Refresh buttons.
Why
When users click 🔄 Refresh in the Telegram bot (usage, client info, IP logs, onlines),
editMessageTextandeditMessageReplyMarkupare always called even when the data hasn't changed. Telegram returns a 400 error (message is not modified), which was logged asWarning— cluttering the logs on every single refresh click.Type of change
Areas affected
How was this tested?
TestIsTelegramNotModifiedErrorverifies the helper correctly identifies "not modified" and "No fields to modify" errors while rejecting unrelated errors.gofmtpasses. Fullgo testrequires GCC (CGo/SQLite) which is available on CI.Screenshots / recordings
N/A
Breaking changes
None
Checklist
go build ./...and the test suite pass locally. (requires GCC/MinGW — CI will verify)npm run lint,npm run typecheck, andnpm run buildpass.