Add optional on_error/4 callback to SessionHandler#23
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add OpenSpec change artifacts for the on_error/4 optional callback on SessionHandler. Session calls on_error directly for protocol errors (garbled messages, heartbeat timeouts), SessionWorker for transport errors (connect/send failures). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduce an optional `on_error/4` callback that notifies handlers of session-level errors: :connect_error, :transport_error, :garbled_message, and :heartbeat_timeout. The callback is guarded with function_exported? and wrapped in try/rescue so handlers that don't implement it are unaffected and raising handlers can't crash the session. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Free Tier Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| Logger.error(fn -> | ||
| "[fix.error] [#{session_name}] on_error callback raised: #{inspect(e)}" | ||
| end) | ||
| end |
There was a problem hiding this comment.
Duplicated error notification pattern across session module
Low Severity
The function_exported? + try/rescue + Logger.error pattern for invoking on_error is copy-pasted twice inline in session.ex (for :heartbeat_timeout and :garbled_message), while session_worker.ex correctly extracts the identical logic into a reusable maybe_notify_error/5 helper. A similar private helper in session.ex would eliminate the duplication and keep the error-handling contract consistent across both modules.
Additional Locations (2)
Archive the completed callback-on-error change (16/16 tasks done) and sync the error-callback delta spec to openspec/specs/. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>


Summary
on_error/4callback to theSessionHandlerbehaviour that notifies handlers of session-level errors:connect_error,:transport_error,:garbled_message, and:heartbeat_timeoutError types
:connect_errorSessionWorker— TCP/SSL connect fails%{reason: term()}:transport_errorSessionWorker—transport.sendfails%{reason: term()}:garbled_messageSession— checksum/body-length validation fails%{raw_message: binary()}:heartbeat_timeoutSession— second consecutive RX timeout%{}Test plan
on_error/4receives:garbled_messageon garbled FIX messageson_error/4does not crash on garbled messages:connect_errordispatched whentransport.connectfails:transport_errordispatched whentransport.sendreturns error:heartbeat_timeoutdispatched on second consecutive RX timeouton_error/4handler is rescued without crashing the sessionmix credoandmix dialyzerpass with no new warningsNote
Medium Risk
Touches core session and transport code paths (timeouts, invalid message handling, and socket send/connect), which could affect runtime behavior under error conditions. The callback is optional and guarded/rescued, reducing risk but still introducing new side effects and logging in failure paths.
Overview
Adds a new optional error-notification callback
ExFix.SessionHandler.on_error/4(declared via@optional_callbacks) to let applications react programmatically to session/transport failures.Sessionnow invokeson_error/4for:garbled_messageand:heartbeat_timeout(second consecutive RX timeout) with guardedfunction_exported?/3checks andtry/rescuelogging.SessionWorkernow checkstransport.send/2results and notifies:transport_error, and also notifies:connect_errorwhen socket connect fails, via a sharedmaybe_notify_error/5helper.Adds/updates test handlers and new unit tests covering each error type, optional-callback behavior, and handler exceptions; also adds OpenSpec specs/archive docs plus small repo hygiene updates (
CLAUDE.md,.gitignorefor/.serena/).Written by Cursor Bugbot for commit 9811156. This will update automatically on new commits. Configure here.