Are you an LLM? You can read better optimized documentation at /protocols/sbp/errors.md for this page in Markdown format
SBP Error Model (v1)
Authority: Primary (Normative)
Purpose: Error taxonomy, codes, sender/receiver contracts, and retryability for SBP.
Defines canonical error semantics for @sideband/protocol, independent of transport. Error frames are part of the public contract; transports MAY also surface transport-native errors (e.g. WebSocket close codes) but must map protocol failures to ErrorFrame.
Error taxonomy
SBP defines error codes in the 1000–1099 range:
| Code | Name | Fatality | Semantics |
|---|---|---|---|
| 1000 | ProtocolViolation | Fatal | Generic protocol contract violation |
| 1001 | UnsupportedVersion | Fatal | Peer advertised incompatible version |
| 1002 | InvalidFrame | Contextual | Frame structure or encoding error |
| 1003 | UnsupportedFeature | Non-fatal | Feature reserved or requires capability exchange |
Application errors use range 2000+. ApplicationError (2000) is a catch‑all; higher-level layers may define stable subcodes via metadata or payload.
See Error Code Registry for the canonical code definitions and RPC-layer codes.
Error frame shape (binary)
ErrorFrame(t=3):code:uint16 LE,msgLen:uint32 LE,message:UTF-8, optional opaquedetails(e.g. JSON/CBOR details).idSHOULD mirror the failing frame'sidwhen correlating to a request/response; absent otherwise.tsOPTIONAL for diagnostics.
Contract for senders
- Use the narrowest code available; avoid overloading
ApplicationErrorfor protocol faults. - Message text SHOULD be short and stable enough for logs; do not leak secrets.
- On version mismatch during handshake: send
UnsupportedVersionthen close. - On malformed input: send
InvalidFramewith context inmessage;detailsMAY include a structured schema error. - When closing after a fatal error, prefer sending an
ErrorFramebeforeControl:Closeunless the transport is already unusable.
Contract for receivers
- Treat
ProtocolViolationandUnsupportedVersionas fatal; close the transport after emitting diagnostics. InvalidFrameMAY be fatal or MAY trigger best-effort recovery if the frame boundary is intact; if recovery is unsafe, close.UnsupportedFeatureis non-fatal; continue processing subsequent frames. The feature is valid but unavailable in this version or capability set.ApplicationErroris non-fatal to the transport; the caller decides whether to retry.- If
idis present, route the error to the correlated request/stream; otherwise emit as connection-level fault.
Retryability and mapping
- Retryable: typically
ApplicationErrorwith explicit higher-level hint; protocol spec itself is neutral. - Non-retryable:
UnsupportedVersion, repeatedProtocolViolation, structurally invalid frames. - WebSocket mapping (guidance):
- Close with
1002(protocol error) forProtocolViolation/InvalidFrame. - Close with
1003(unsupported data) forUnsupportedVersion. - Preserve
ErrorFrame.messagein close reason when size allows; otherwise emit to logs only.
- Close with
Security considerations
- Size: receivers MAY cap
ErrorFrame.details(e.g. ≤ 16 KiB) to prevent abuse. - Untrusted text: treat
messageas untrusted; escape before surfacing in UIs. - Rate limit: throttle repeated errors from a peer to avoid log/CPU DoS.