Skip to content

hotfix: improve LNbits error handling and filter empty telebot errors#60

Merged
helloscoopa merged 1 commit intomainfrom
hotfix/error-handling-fixes
Mar 25, 2026
Merged

hotfix: improve LNbits error handling and filter empty telebot errors#60
helloscoopa merged 1 commit intomainfrom
hotfix/error-handling-fixes

Conversation

@xbuddhi
Copy link
Copy Markdown

@xbuddhi xbuddhi commented Mar 25, 2026

Summary

  • Add parseLNbitsError helper for robust error extraction (captures HTTP status code, raw body, and alternate message fields) — replaces boilerplate across 8 call sites
  • Filter empty/ghost telebot errors ({"message":"","Err":{},"code":0}) from OnError handler and ErrorLogger
  • Add null-safe ctx checks in OnError to prevent panics when context is nil
  • Add /health endpoint for monitoring

What's NOT included

This is a targeted hotfix extracted from the dev branch. It deliberately excludes:

  • Analytics API endpoints and configuration
  • Standing order feature
  • Any new dependencies or schema changes

Test plan

  • Verify empty telebot errors no longer appear in TG error log group
  • Verify real LNbits errors (e.g. insufficient balance) still get logged with full details
  • Verify /health endpoint returns 200 OK
  • Verify bot starts and operates normally

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved error reporting for external API interactions
    • Reduced spurious error notifications from internal processes
  • New Features

    • Added health check endpoint for system monitoring

- Add parseLNbitsError helper for robust error extraction (captures HTTP status, raw body, alternate message fields)
- Filter empty/ghost telebot errors (code:0, empty message) in OnError handler and ErrorLogger
- Add null-safe ctx checks in OnError to prevent panics
- Add /health endpoint for monitoring

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR enhances error handling across LNbits integration and Telegram error logging. It introduces a helper function to parse LNbits HTTP errors consistently with status codes and response bodies, extends the Error struct to capture additional context, improves Telegram error filtering to skip empty/ghost errors with nil-safety checks, and adds a health check endpoint to the API server.

Changes

Cohort / File(s) Summary
LNbits error handling
internal/lnbits/lnbits.go, internal/lnbits/types.go
Added parseLNbitsError() helper to consolidate error parsing from HTTP responses. Enhanced Error struct with Message, StatusCode, and RawBody fields. Updated error formatting logic to prioritize Detail, then Message, then construct descriptive messages from status code and raw body.
Telegram error logging
internal/telegram/error_logger.go, main.go
Improved error filtering to detect and skip empty/ghost JSON error patterns. Enhanced LogError to compute error string and short-circuit on empty messages. Updated Telegram bot OnError handler with nil checks for context before accessing Sender/Chat.
API infrastructure
main.go
Added HTTP GET /health route returning 200 OK with OK body for health checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Review effort 3/5

Suggested reviewers

  • helloscoopa

Poem

🐰 Whiskers twitching with delight,
Error messages now feel right!
LNbits errors caught with care,
Ghost errors vanish into air, 🎯
Health checks bounce along the way!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: improved LNbits error handling and filtering of empty telebot errors, which are the primary objectives across the four modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/error-handling-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@helloscoopa helloscoopa merged commit 17ce82d into main Mar 25, 2026
3 of 4 checks passed
@helloscoopa helloscoopa deleted the hotfix/error-handling-fixes branch March 25, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants