d34185b56c
# Conflicts: # app/lib/features/chat/conversation/chat_thread_view.dart # app/tool/perf/perf_fixture.dart # internal/protocol/chat.go # internal/server/chat_close.go # internal/server/chat_sessions.go
24 lines
990 B
Dart
24 lines
990 B
Dart
/// The reason text carried by a failed request, without runtime diagnostics.
|
|
///
|
|
/// The gateway fails pending requests with `StateError('Connection closed')`,
|
|
/// whose `toString()` is `Bad state: Connection closed`. The browser shows the
|
|
/// reason itself, never a Dart diagnostic, so those prefixes are stripped while
|
|
/// deliberate protocol/refusal messages stay untouched. [fallback] is the
|
|
/// honest sentence for a failure that carries no text at all.
|
|
String describeErrorReason(Object error, {required String fallback}) {
|
|
final raw = switch (error) {
|
|
StateError(:final message) => message.toString(),
|
|
_ => '$error',
|
|
};
|
|
var message = raw.trim();
|
|
for (final prefix in _runtimePrefixes) {
|
|
if (message.startsWith(prefix)) {
|
|
message = message.substring(prefix.length).trim();
|
|
}
|
|
}
|
|
return message.isEmpty ? fallback : message;
|
|
}
|
|
|
|
/// Dart runtime prefixes that never belong in operator-facing copy.
|
|
const _runtimePrefixes = ['Bad state:', 'Exception:'];
|