Files
buzz/mobile/lib/shared/relay/relay_error_text.dart
Tom Brow d29c679066 fix(mobile): keep error names in send, upload and invite failure text (#9855)
## Summary

The compose bar's send error, the upload error and the invite page's
error removed the first `Exception: ` anywhere in an error's text, not
just a leading one. A `TimeoutException` read "Timeout..." and a wrapped
error lost part of its text.

They now share the helper Add Members already uses: only a plain
`Exception`'s leading prefix is removed, a relay rejection shows its
message verbatim, a lost acknowledgement drops the prefix only from its
cause, and named types such as `TimeoutException` keep their whole name.
The helper moves to `shared/relay/relay_error_text.dart`; Add Members
behaves as before.

## Validation

- New `relay_error_text_test.dart` covers a plain `Exception`, a
`TimeoutException`, a named error whose message contains `Exception: `,
a relay rejection and a lost acknowledgement. The `TimeoutException` and
named-error rows fail with the old `replaceFirst`.

No screenshots: the change only affects text after a failed send, upload
or invite, which can't be triggered on demand against a real relay.

Full-app run on an iOS simulator (signed in, healthy relay): cold start
and session restore, channel list, opening a channel, sending a message,
the attachment button, Settings, and background then foreground. All
passed with no new errors in the device log. The invite page isn't
offered to the test account.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
2026-11-22 08:00:17 -08:00

26 lines
1.1 KiB
Dart

import 'relay_session_types.dart';
import 'relay_socket.dart';
/// The text of [error] for showing to the person, without the `Exception: `
/// a plain [Exception] adds. A relay rejection keeps its message verbatim,
/// and a lost acknowledgement drops the prefix only from its cause. Named
/// types keep their whole name: `TimeoutException: ...` stays as is.
///
/// Use this where any error can reach the person and its text should stay
/// whole. For a relay refusal reworded as a sentence (NIP-01 prefix dropped,
/// first letter capitalized), use `relayErrorMessage` instead.
String relayErrorText(Object error) {
if (error is RelayEventRejectedException) return error.message;
final text = error.toString();
final cause = error is RelayAckLostError ? error.cause : null;
if (cause != null) {
final causeText = cause.toString();
if (text.endsWith(causeText)) {
return text.substring(0, text.length - causeText.length) +
relayErrorText(cause);
}
}
const prefix = 'Exception: ';
return text.startsWith(prefix) ? text.substring(prefix.length) : text;
}