Skip to content

Adopt StructuredError bubbling standard (observability producer) - #13

Merged
AquiGorka merged 2 commits into
mainfrom
fix/structured-errors
Jul 8, 2026
Merged

Adopt StructuredError bubbling standard (observability producer)#13
AquiGorka merged 2 commits into
mainfrom
fix/structured-errors

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

Adopts the StructuredError error-bubbling standard (already live on provider-platform / pay-platform) on network-dashboard-platform — the producer side of this coordinated pair. Errors are wrapped with context preserving the native cause chain into logs, and a client-safe { code, source, message } shape is what leaves the edge (here, the network WebSocket).

The SDK does not export a StructuredError type, so the shape is defined locally (src/error/structured-error.ts), matching the standard's contract.

What changed

  • StructuredError (new, local): carries code + source + native cause; toWire() projects the client-safe shape; idempotent static from() wraps a raw error while preserving it as the cause.
  • Logger error() now flattens the .cause chain into outer <- inner <- root, so a wrapped error logs its full context (mirrors provider-platform's flattenCauses).
  • council-fetch throws StructuredErrorCOUNCIL_PLATFORM_HTTP_ERROR on non-OK, COUNCIL_PLATFORM_UNREACHABLE (cause preserved) on network/timeout.
  • env config throws StructuredError (ENV_MISSING / ENV_INVALID_NETWORK).
  • topology-refresh wraps failures as TOPOLOGY_REFRESH_FAILED (council error as cause → full chain in logs) and broadcasts a client-safe error frame on the bus.
  • bus gains a structured-error channel (subscribeErrors / publishError).
  • network WS gains an additive { type: "error", error } frame. No subprotocol bump: it's a new frame type, so older SPAs drop it via parseServerFrame rather than mis-render — a platform-first deploy won't disconnect not-yet-updated clients. The 426 body is also structured.

The /public/rpc JSON-RPC error envelope (-32xxx) is left as-is — that's a protocol standard, not this service's own error shape.

Consumer

network-dashboard reads StructuredError.code from the new error frame and maps it to operator copy (its PR consumes this wire contract).

Tests

deno check / lint / fmt / test green. New: StructuredError (wrap/idempotent/toWire), logger cause-chain flattening, topology-refresh error broadcast, WS error-frame delivery + unsubscribe-on-close. 46 tests pass.

Version bump 0.1.13 → 0.1.14 (own commit).

AquiGorka added 2 commits July 6, 2026 13:31
Wrap internal errors with context preserving the native cause chain into
logs, and surface a client-safe { code, source, message } shape at the
edge — mirroring the standard already live on provider-platform.

- add local StructuredError (SDK does not export one): carries code +
  source + native cause; toWire() projects the client-safe shape; static
  from() wraps a raw error idempotently, preserving it as the cause.
- logger.error() flattens the cause chain (outer <- inner <- root) so a
  wrapped error logs its full context, not just the outermost message.
- council-fetch throws StructuredError (COUNCIL_PLATFORM_HTTP_ERROR /
  _UNREACHABLE); env config throws StructuredError (ENV_MISSING /
  _INVALID_NETWORK).
- topology-refresh wraps failures as TOPOLOGY_REFRESH_FAILED and
  broadcasts a client-safe error frame on the bus.
- network WS gains an additive { type: "error", error } frame (no
  subprotocol bump: old SPAs drop unknown frames); 426 body structured.
- bus gains a structured-error channel (subscribeErrors/publishError).
@AquiGorka
AquiGorka requested a review from pselle July 6, 2026 18:05
@AquiGorka
AquiGorka merged commit 4fbf1e1 into main Jul 8, 2026
5 checks passed
@AquiGorka
AquiGorka deleted the fix/structured-errors branch July 8, 2026 11:35
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