The Talk room list crashed for a new account because the server omits
lastMessage for rooms without a visible message and the model required it.
Beyond that single field, a review of the Talk models against the OpenAPI
spec of the installed version (23.0.8) found the same crash class in several
places: closed enums over open server values (inCall bitmask, rich-object
types, actor and message types), a deleted parent sent as {id, deleted},
and the autocomplete status arriving as an object.
- json_serializable `checked: true`: decode errors now name class and field
- lists (rooms, messages, participants, autocomplete) decode per entry;
a malformed entry is skipped and reported via ClientErrorReporter
- unknownEnumValue fallbacks for all response enums of Talk and breakers
- lastMessage nullable; inCall as bitmask; deleted parent placeholder;
autocomplete status object/string; fixed shareWithDisplayNameUnique key
- GetRoomParams no longer sends null query parameters
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HrepDTL4qDe35TuS29sLW3
47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
import 'package:json_annotation/json_annotation.dart';
|
|
|
|
/// Decodes server lists element by element so one entry the model cannot map
|
|
/// (a field the server dropped, an enum value it added) is skipped and
|
|
/// recorded instead of failing the whole response and with it the screen.
|
|
///
|
|
/// Skipped entries are collected per isolate; the API layer drains them with
|
|
/// [drainDecodeWarnings] and reports them, so a drift in the server's format
|
|
/// still reaches us without taking the feature down for the user.
|
|
final List<String> _warnings = [];
|
|
|
|
List<T> decodeListLenient<T>(
|
|
Object? raw,
|
|
T Function(Map<String, dynamic>) fromJson, {
|
|
required String what,
|
|
}) {
|
|
final items = <T>[];
|
|
if (raw is! List<dynamic>) {
|
|
throw FormatException(
|
|
'expected a list of ${what}s, got ${raw.runtimeType}',
|
|
);
|
|
}
|
|
for (final entry in raw) {
|
|
try {
|
|
items.add(fromJson(entry as Map<String, dynamic>));
|
|
} on CheckedFromJsonException catch (e) {
|
|
_warnings.add('$what: $e');
|
|
} on TypeError catch (e) {
|
|
_warnings.add('$what: $e');
|
|
}
|
|
}
|
|
return items;
|
|
}
|
|
|
|
Set<T> decodeSetLenient<T>(
|
|
Object? raw,
|
|
T Function(Map<String, dynamic>) fromJson, {
|
|
required String what,
|
|
}) => decodeListLenient(raw, fromJson, what: what).toSet();
|
|
|
|
/// Returns and clears the entries skipped since the last call.
|
|
List<String> drainDecodeWarnings() {
|
|
final out = List<String>.of(_warnings);
|
|
_warnings.clear();
|
|
return out;
|
|
}
|