Files
buzz/mobile/lib/shared/relay/relay.dart
Tom Brow 0966f3fad6 feat(mobile): tag escaped relay errors with their call and reason class (#9821)
Makes relay errors that nothing catches readable in diagnostic reports.
Today an unhandled relay rejection or timeout arrives with its text
removed and a stack that stops at the async error handler, so a report
can't say which call failed or why.

## Changes

- **Typed call and reason:** relay errors now carry the call (`publish`,
`query`, `history`, `subscribe`) and a fixed reason class taken from the
relay's reason prefix (`invalid`, `rate-limited`, `restricted`,
`auth-required`, `blocked`, `duplicate`, `pow`, `unsupported`, `error`,
`timeout`, or `other`). Types:
  - `RelayEventRejectedException` implements the new `RelayCallError`;
- new `RelayTimeoutException` extends `TimeoutException`, and
`RelayAckTimeoutError` now extends it;
- new `RelayClosedException` replaces the plain `Exception` for a closed
history or live subscription, with the same `toString`.
- new `RelayQueryException` (a `RelayException` that is also a
`RelayCallError`) for a non-2xx `/query` answer, with its reason from
the status alone;
- a one-shot signed event the relay refuses now fails with a typed
rejection, with the same text.
Existing `TimeoutException` checks and message helpers behave as before.
- **Report tags:** before the filter runs, a report whose error is a
`RelayCallError` gets `relay.call` and `relay.reason` tags. The relay's
own text is never sent. These reports are also grouped by call and
reason on top of the default grouping, so a rate limit and an invalid
request from the same code become separate issues.
- **Call-site stack:** pending publishes, one-shot signed events, and
history and live subscriptions keep the stack where they were created,
and errors completed later from timers or socket callbacks use it. A
report's stack now reaches the calling code.
- **Spec:** one bullet on the tags, the grouping and the stack.

## Validation

New tests:
- a table of reason prefixes to classes;
- error types, fields and the existing message helpers;
- relay session cases: a rejected publish's call, reason and calling
stack, the timeout types, and closed subscriptions;
- reports: tags, the grouping key, no relay text, and non-relay errors
untouched.
- production refusals through a serialized report: `/query` statuses,
snapshot `/query` versus discovery, and one-shot rejections and timeouts
with the caller's stack.


Full-app run on an iOS simulator (signed in, healthy relay): cold start
and session restore, channel list, opening channels and DMs, history
back to each channel's start, send, react, edit, thread reply, search,
channel details and Add Members, Settings > Send test report, and
background then foreground followed by a send and a delete. All passed
with no new errors in the device log, and no doubled error names in any
logged text. Error paths (timeouts, closed connections, relay
rejections) weren't triggered on the healthy relay; the unit tests above
cover them.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
2026-11-24 16:29:14 -08:00

19 lines
568 B
Dart

export 'app_lifecycle_provider.dart';
export 'identity_scoped_prefs.dart';
export 'media_auth.dart';
export 'media_disk_cache.dart';
export 'media_image.dart';
export 'media_upload.dart';
export 'nostr_filters.dart';
export 'nostr_models.dart';
export 'relay_call_error.dart';
export 'relay_closed_policy.dart';
export 'relay_error_text.dart';
export 'relay_client.dart';
export 'relay_provider.dart';
export 'relay_rate_limit_gate.dart';
export 'relay_reconnect_policy.dart';
export 'relay_session.dart';
export 'relay_socket.dart';
export 'signed_event_relay.dart';