Skip to content

feat: report unhandled errors via toast and configurable webhook - #9

Open
tabedzki wants to merge 1 commit into
mainfrom
tabedzki/feat/error-reporting
Open

tabedzki wants to merge 1 commit into
mainfrom
tabedzki/feat/error-reporting

Conversation

@tabedzki

Copy link
Copy Markdown
Owner

🤖 Human guided, AI assisted PR (using this skill). AI text below. 🤖

Summary

Unhandled errors can no longer crash a session or the server. Each one is logged with its traceback, shown to the affected user as an error toast, and optionally POSTed to a webhook that the deployer configures.

All of this lives in the new pixelmap/error_reporting.py:

  • Panel callbacks (buttons, widgets, file downloads, async clicks): create_app installs a per-session exception_handler. It has to be per session for the same reason as notifications=True: Panel keys config on the current document. Because the handler returns instead of re-raising, Bokeh no longer discards the document writes the callback made before it failed.
  • Raw Bokeh on_change callbacks: Panel's handler doesn't see these. The two in gui.py (electrode selection and tool state) are now wrapped with guarded(...), and a test enforces that.
  • Session startup: if the app fails to build, the visitor gets an error alert instead of a blank page.
  • Background threads, the asyncio loop and sys.excepthook: these are reported to the webhook but not toasted, since no session is attached.

Webhook configuration

Env var Default Meaning
PIXELMAP_ERROR_WEBHOOK_URL unset (off) http(s) endpoint; any other scheme is rejected
PIXELMAP_ERROR_WEBHOOK_TOKEN unset sent as Authorization: Bearer <token>
PIXELMAP_ERROR_WEBHOOK_TIMEOUT 5 seconds before a send is abandoned
PIXELMAP_ERROR_WEBHOOK_DEDUPE_SECONDS 60 the same error (type + message + location) is sent at most once per window; 0 sends every one

The payload has a one-line text/content summary, so Slack, Mattermost and Discord incoming webhooks work as-is. It also has an event object with the type, message, traceback, session id, host and version. Sends run on a single daemon thread with a bounded queue. A slow or dead endpoint therefore can't block the Bokeh event loop or grow memory: excess reports are dropped, and failed sends are only logged. The settings are documented in docs/getting-started.md, env.template and docker-compose.yml.

Testing

  • tests/test_error_reporting.py adds 54 tests, written before the implementation. They cover blank and invalid settings, non-http URLs, timeout values of 0, negative, NaN and infinity, errors whose message can't be printed, a missing or broken toast area, a sender that raises, duplicate suppression, a full queue, and real delivery to a local HTTP server.
  • Full suite: 576 passed.
  • Manual end-to-end check in headless Chrome against a served app whose callback raises:
    • the toast appears;
    • the write made just before the raise still reaches the browser;
    • later interactions keep working;
    • the webhook receives each error with the bearer token.
  • The real PixelMap app loads with no server or JS errors.

Notes

  • Callback errors show up twice in the server log, because Panel logs its own traceback before ours.
  • Errors the app already handles (bad uploads, failed atlas downloads) keep their existing toasts and are not sent to the webhook.

Assisted-by: ClaudeCode:claude-opus-5-5

Route every unhandled error through a new pixelmap.error_reporting module
so that it can no longer crash a session or the server:

- Panel callbacks: create_app installs a per-session exception_handler
  that logs the traceback, shows an error toast and posts to the webhook.
  Returning instead of re-raising also keeps Bokeh from discarding the
  document writes the callback already made.
- Raw Bokeh on_change callbacks (electrode selection, tool state), which
  Panel's handler does not see, are wrapped with `guarded`.
- A failing session build renders an error alert instead of a blank page.
- Background threads, the asyncio loop and sys.excepthook report to the
  webhook (no toast, as no session is attached).

The webhook is opt-in via PIXELMAP_ERROR_WEBHOOK_URL (http(s) only), with
optional _TOKEN (bearer auth), _TIMEOUT and _DEDUPE_SECONDS. Payloads carry
Slack/Discord-compatible `text`/`content` summaries plus a structured
`event`. Delivery runs on a daemon thread with a bounded queue, so a slow
or dead endpoint cannot block the event loop or grow memory.

Assisted-by: ClaudeCode:claude-opus-5-5
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.

1 participant