File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,6 +47,13 @@ class Recordings {
4747 factory Recordings .fromJson (Map <String , Object ?> json) {
4848 try {
4949 final syntax = RecordedUsesSyntax .fromJson (json);
50+ final syntaxErrors = syntax.validate ();
51+ if (syntaxErrors.isNotEmpty) {
52+ final errorsString = syntaxErrors.map ((e) => ' - $e ' ).join ('\n ' );
53+ throw FormatException (
54+ 'Validation errors for record use file:\n $errorsString \n ' ,
55+ );
56+ }
5057 return Recordings ._fromSyntax (syntax);
5158 } on FormatException catch (e) {
5259 throw FormatException ('''
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import 'package:record_use/record_use_internal.dart' ;
6+ import 'package:test/test.dart' ;
7+
8+ import '../test_data.dart' ;
9+
10+ void main () {
11+ group ('Recordings.fromJson validation' , () {
12+ test ('Recordings.fromJson fails for invalid JSON' , () {
13+ final json = recordedUses.toJson ();
14+ // Modify the first recording's identifier URI to be an invalid type.
15+ final recordings = json['recordings' ] as List ;
16+ final recording = recordings[0 ] as Map ;
17+ final identifier = recording['identifier' ] as Map ;
18+ identifier['uri' ] = 123 ; // Should be a string
19+
20+ expect (
21+ () => Recordings .fromJson (json),
22+ throwsA (
23+ isA <FormatException >().having (
24+ (e) => e.message,
25+ 'message' ,
26+ contains ('Validation errors for record use file:' ),
27+ ),
28+ ),
29+ );
30+ });
31+ });
32+ }
You can’t perform that action at this time.
0 commit comments