Skip to content

Map structured errors to operator copy via a WS banner#22

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

Map structured errors to operator copy via a WS banner#22
AquiGorka merged 2 commits into
mainfrom
fix/structured-errors

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

Consumer side of the coordinated StructuredError adoption (pairs with network-dashboard-platform#13). The dashboard's only backend link is the network WebSocket, so structured errors ride it too — the "structured-error path" here is the WS payload, not an HTTP body. Two error sources, both surfaced through one shape-agnostic mapper:

  1. Transport errors (connect fail / drop / reconnect) — previously a silent console.warn plus a hardcoded generic banner that wasn't even wired up.
  2. { type: "error" } frames the backend now pushes over the socket (e.g. a failed council-platform topology refresh) — the connection is still live but some data may be degraded.

What changed

  • lib/error-copy.ts (new): errorCopy() mirroring moonlight-pay's friendlyError — known code → copy, else a safe server message (guarded by isSafeSentence), else a generic fallback. Reads .code regardless of which backend produced it, so a council-platform code bubbled through network-dashboard-platform maps the same as a native one.
  • network-events: adds the StructuredError type + the additive { type: "error" } frame; parseServerFrame validates it (mirrors the backend, no subprotocol bump).
  • ws-client: onError handler; onmessage switches over frame type.
  • dom.renderError: now displays the (mapped) message instead of the old hardcoded string, keeping the generic sentence only as an empty-message fallback.
  • app.ts: a connection / degraded-data banner wired to both transport status (closed/not-configured → mapped copy; cleared on open) and backend error frames, all through the mapper.

No new REST path / CSP / config changes — errors ride the existing WebSocket. Council-platform failures reach the SPA via the backend's TOPOLOGY_REFRESH_FAILED frame; the mapper stays shape-agnostic so any upstream code maps.

Tests

deno check / lint / fmt / dev+prod build / test green. New: errorCopy mapper (known/unknown code, safe-message passthrough, unsafe-message rejection, transport codes, code-over-message), error-frame parsing, and renderError now-displays-mapped-copy + fallback. 25 tests pass.

Version bump 0.2.15 → 0.2.16 (own commit).

Merge order

Merge after network-dashboard-platform#13 (platform anchors the wire contract).

AquiGorka added 2 commits July 6, 2026 14:01
The dashboard's only backend link is the network WebSocket, so structured
errors ride it too — from two sources, both surfaced through one mapper:

- transport errors (connect fail / drop / reconnect), previously a silent
  console.warn plus an unwired hardcoded banner; and
- { type: "error" } frames the backend now pushes over the socket (e.g. a
  failed council-platform topology refresh).

- add lib/error-copy.ts: shape-agnostic errorCopy() mirroring moonlight-pay
  friendlyError — known code -> copy, else a safe server message, else a
  generic fallback. Reads .code regardless of which backend produced it.
- network-events: add the StructuredError type + additive { type: "error" }
  frame; parseServerFrame validates it.
- ws-client: onError handler; switch over frame type.
- dom.renderError now DISPLAYS the (mapped) message instead of a hardcoded
  string, keeping the generic sentence only as an empty-message fallback.
- app.ts: a connection/degraded-data banner wired to both transport status
  and backend error frames through the mapper.
@AquiGorka AquiGorka requested a review from pselle July 6, 2026 18:05
@AquiGorka AquiGorka merged commit c24be73 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