You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(types): replace unsafe explicit type casting and JSON map casts with pattern-matching validation #1510
A static search across lib/ identified 245 unchecked explicit casts (as Map, as List, as String, etc.).
Most notably, in lib/core/extensions/local_extension_registry.dart:57:
final json =jsonDecode(content) asMap<String, dynamic>;
If a manifest file on disk contains a JSON array ([...]), a primitive value, or invalid formatting, this throws an unhandled TypeError at runtime (List<dynamic> is not a subtype of type Map<String, dynamic>).
Similarly, in lib/core/team/team_profile.dart (lines 129–137) and lib/core/erd/erd_saved_layout.dart (lines 172–181), values extracted from untyped maps are cast directly via item['field'] as String? without validating against corrupt database records.
Proposed Solution
Use Dart 3 pattern-matching type guards for JSON deserialization:
final decoded =jsonDecode(content);
if (decoded is!Map<String, dynamic>) {
throwFormatException('Expected JSON object, got ${decoded.runtimeType}');
}
Introduce a safe map extraction helper (e.g. asStringOrNull(), asIntOrNull()) for config/profile parsing.
Replace raw as List<dynamic> casts with List<dynamic>.from(...) or typed collection checks.
Acceptance Criteria
Corrupted or unexpected JSON manifests / layout files produce clear diagnostic errors rather than unhandled TypeError crashes.
Safe type extraction helpers are used across extension and profile deserializers.
Activity