mirror of
https://github.com/block/buzz.git
synced 2026-11-30 13:12:38 +00:00
Follow-ups to the mobile diagnostic reporting work in
docs/mobile-diagnostic-reporting.md.
## Changes
- **Install ID repair:** if the install ID file holds something that
isn't text, the app now replaces it with a new ID, as it already does
for an empty file. Before, every report went out without an install ID.
A read that fails (for example, no file descriptor free) still keeps the
file, so a passing error never replaces a good ID.
- **Clock-window refusals are not reported as errors:** the spec treats
relay refusals for a timestamp outside the relay's clock window as
expected (counting them is still pending). The app only recognized one
of the relay's wordings ("timestamp too far from server time"), so
refusals for canvas events, relay-admin commands, leave requests and
observer frames were reported as invalid requests. The five wordings are
matched from the start of the reason, so unrelated `invalid:` reasons
that mention a timestamp, such as the feedback timestamp overflow or one
that echoes a value, are still reported.
- **Diagnostics card:** rows get subtitles, and the divider indent
matches the neighbouring Settings cards.
- **Comments:** explain why push stop gates its current-identity request
on the community key, and correct a test comment about who drops a
repeated error object.
## Validation
New tests cover:
- member attribution on relay sessions, including a missing key and an
answer that arrives after the member changed;
- push stop reports while signed out;
- reporter wiring for hosted admission and the self-hosted probe;
- frames the socket can't decode;
- a table of relay refusal reasons, each either reported or not, for
both `OK` and `CLOSED`;
- an install ID file whose reads fail keeps its ID.
Full-app run on an iPhone 17 Pro simulator at 61b04f6: startup, channel
list, sending and reacting, Settings, the Diagnostics card and Send test
report, and install ID repair (a file that isn't valid UTF-8 and an
empty file each got a new ID that stayed the same on the next launch).
Not covered: a relay clock-window refusal, which the live relay would
not produce.
## Diagnostics card
| Before | After |
| --- | --- |
| 
| 
|
---------
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
208 lines
5.6 KiB
Dart
208 lines
5.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
/// The one interface app code uses for diagnostic reporting.
|
|
///
|
|
/// See `docs/mobile-diagnostic-reporting.md`. Every call returns at once and
|
|
/// never throws: a failure inside reporting is dropped so it cannot reach the
|
|
/// code that made the call.
|
|
abstract interface class DiagnosticReporter {
|
|
/// Reports something that should never happen, such as a frame the app
|
|
/// cannot decode. [operation] names where it happened, from a fixed list.
|
|
void reportError(
|
|
Object error,
|
|
StackTrace? stackTrace, {
|
|
required DiagnosticOperation operation,
|
|
});
|
|
|
|
/// Counts one networking event, with how long it took when known.
|
|
void countNetworkEvent(NetworkEvent event);
|
|
|
|
/// Adds one entry to the trail attached to later reports.
|
|
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb);
|
|
|
|
/// Attributes later reports and counts to [pubkey], or to no one.
|
|
void setMember(String? pubkey);
|
|
|
|
/// The member later reports and counts name, as last given to [setMember].
|
|
String? get member;
|
|
|
|
/// Whether this build has a reporting destination. Only then does Settings
|
|
/// offer the checks below.
|
|
bool get reporting;
|
|
|
|
/// Sends a [DiagnosticTestError], to check a build's reporting end to end.
|
|
void sendTestReport();
|
|
|
|
/// Crashes the app in native code, to check native crash reports.
|
|
void crashForTest();
|
|
}
|
|
|
|
/// The error a test report carries, so it is easy to tell apart.
|
|
///
|
|
/// Not const: each report needs its own instance, or the SDK's own
|
|
/// deduplication drops a repeat of the last error object.
|
|
class DiagnosticTestError implements Exception {
|
|
DiagnosticTestError();
|
|
|
|
@override
|
|
String toString() => 'DiagnosticTestError';
|
|
}
|
|
|
|
/// Where an explicit error report comes from.
|
|
enum DiagnosticOperation {
|
|
relayFrame,
|
|
relayQuery,
|
|
relayRejection,
|
|
accountResponse,
|
|
pushGatewayResponse,
|
|
storedData,
|
|
eventSubscriber,
|
|
testReport,
|
|
}
|
|
|
|
/// The operation a networking event belongs to.
|
|
enum NetworkEndpoint { relayConnection, relayQuery, relayPublish }
|
|
|
|
/// How a networking event ended.
|
|
enum NetworkOutcome { success, failure }
|
|
|
|
/// Why a networking event failed.
|
|
enum NetworkFailure {
|
|
timeout,
|
|
disconnected,
|
|
offline,
|
|
unreachable,
|
|
insecure,
|
|
rateLimited,
|
|
authRefused,
|
|
serverError,
|
|
relayError,
|
|
relayRefused,
|
|
}
|
|
|
|
/// One counted networking event. [backend] is the server's host name.
|
|
class NetworkEvent {
|
|
const NetworkEvent({
|
|
required this.backend,
|
|
required this.endpoint,
|
|
required this.outcome,
|
|
this.failure,
|
|
this.duration,
|
|
}) : assert((outcome == NetworkOutcome.failure) == (failure != null));
|
|
|
|
final String backend;
|
|
final NetworkEndpoint endpoint;
|
|
final NetworkOutcome outcome;
|
|
final NetworkFailure? failure;
|
|
final Duration? duration;
|
|
}
|
|
|
|
/// One entry in the trail of recent networking events.
|
|
class DiagnosticBreadcrumb {
|
|
const DiagnosticBreadcrumb(this.event);
|
|
|
|
/// Breadcrumbs from the fixed list are networking events.
|
|
final NetworkEvent event;
|
|
}
|
|
|
|
/// Used when the build has no reporting destination.
|
|
class NoopDiagnosticReporter implements DiagnosticReporter {
|
|
const NoopDiagnosticReporter();
|
|
|
|
@override
|
|
void reportError(
|
|
Object error,
|
|
StackTrace? stackTrace, {
|
|
required DiagnosticOperation operation,
|
|
}) {
|
|
// A throwing subscriber is a bug in the app, and the delivery guard
|
|
// catches it. With no destination, surface it the way an uncaught throw
|
|
// would: it fails the test that hit it and prints in development.
|
|
if (operation == DiagnosticOperation.eventSubscriber) {
|
|
Zone.current.handleUncaughtError(error, stackTrace ?? StackTrace.current);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void countNetworkEvent(NetworkEvent event) {}
|
|
|
|
@override
|
|
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) {}
|
|
|
|
@override
|
|
void setMember(String? pubkey) {}
|
|
|
|
@override
|
|
String? get member => null;
|
|
|
|
@override
|
|
bool get reporting => false;
|
|
|
|
@override
|
|
void sendTestReport() {}
|
|
|
|
@override
|
|
void crashForTest() {}
|
|
}
|
|
|
|
/// Reports from work signed by [signer], such as a one-shot socket for a
|
|
/// community that may not be active. They go through while [reporter] names
|
|
/// [signer] or no member (reports then carry the install identifier), and are
|
|
/// dropped while it names another member, who didn't hit them.
|
|
class SignerDiagnosticReporter implements DiagnosticReporter {
|
|
const SignerDiagnosticReporter(this.reporter, {required this.signer});
|
|
|
|
final DiagnosticReporter reporter;
|
|
final String? signer;
|
|
|
|
bool get _current => switch (reporter.member) {
|
|
null => true,
|
|
final member => member == signer,
|
|
};
|
|
|
|
@override
|
|
void reportError(
|
|
Object error,
|
|
StackTrace? stackTrace, {
|
|
required DiagnosticOperation operation,
|
|
}) {
|
|
if (_current) {
|
|
reporter.reportError(error, stackTrace, operation: operation);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void countNetworkEvent(NetworkEvent event) {
|
|
if (_current) reporter.countNetworkEvent(event);
|
|
}
|
|
|
|
@override
|
|
void leaveBreadcrumb(DiagnosticBreadcrumb breadcrumb) {
|
|
if (_current) reporter.leaveBreadcrumb(breadcrumb);
|
|
}
|
|
|
|
/// Signed work never changes who the app's reports name.
|
|
@override
|
|
void setMember(String? pubkey) {}
|
|
|
|
@override
|
|
String? get member => reporter.member;
|
|
|
|
@override
|
|
bool get reporting => reporter.reporting;
|
|
|
|
@override
|
|
void sendTestReport() => reporter.sendTestReport();
|
|
|
|
@override
|
|
void crashForTest() => reporter.crashForTest();
|
|
}
|
|
|
|
/// The reporter chosen at startup. The root scope overrides it; tests
|
|
/// override it with a fake that records what it was given.
|
|
final diagnosticReporterProvider = Provider<DiagnosticReporter>(
|
|
(ref) => const NoopDiagnosticReporter(),
|
|
);
|