@@ -14,7 +14,7 @@ use JSON::MaybeXS;
14
14
use Syntax::Keyword::Try 0.11;
15
15
use Carp qw( croak carp) ;
16
16
use List::Util 1.55 qw( pairs first uniqint) ;
17
- use Ref::Util 0.100 qw( is_ref is_plain_hashref is_plain_coderef is_plain_arrayref ) ;
17
+ use Ref::Util 0.100 qw( is_ref is_plain_hashref is_plain_coderef) ;
18
18
use Mojo::URL;
19
19
use Safe::Isa;
20
20
use Path::Tiny;
@@ -100,7 +100,11 @@ sub add_schema {
100
100
_evaluator => $self ,
101
101
);
102
102
103
- die [ $document -> errors ] if $document -> has_errors;
103
+ die JSON::Schema::Draft201909::Result-> new(
104
+ output_format => $self -> output_format,
105
+ result => 0,
106
+ errors => [ $document -> errors ],
107
+ ) if $document -> has_errors;
104
108
105
109
if (not grep $_ -> {document } == $document , $self -> _resource_values) {
106
110
my $schema_content = $document -> _serialized_schema
@@ -256,8 +260,8 @@ sub evaluate {
256
260
$result = $self -> _eval($data , $schema , $state );
257
261
}
258
262
catch {
259
- if (is_plain_arrayref( $@ )) {
260
- push @{ $state -> { errors }}, @{ $@ } ;
263
+ if ($@ -> $_isa( ' JSON::Schema::Draft201909::Result ' )) {
264
+ return $@ ;
261
265
}
262
266
elsif ($@ -> $_isa(' JSON::Schema::Draft201909::Error' )) {
263
267
push @{$state -> {errors }}, $@ ;
@@ -458,6 +462,8 @@ sub _get_or_load_resource {
458
462
my $file = path(dist_dir(' JSON-Schema-Draft201909' ), $local_filename );
459
463
my $schema = $self -> _json_decoder-> decode($file -> slurp_raw);
460
464
my $document = JSON::Schema::Draft201909::Document-> new(schema => $schema , _evaluator => $self );
465
+
466
+ # this should be caught by the try/catch in evaluate()
461
467
die [ $document -> errors ] if $document -> has_errors;
462
468
463
469
# we have already performed the appropriate collision checks, so we bypass them here
@@ -675,11 +681,10 @@ You B<MUST> call C<add_schema> for any external resources that a schema may refe
675
681
before calling L</evaluate> , other than the standard metaschemas which are loaded from a local cache
676
682
as needed.
677
683
678
- Returns the L<JSON::Schema::Draft201909::Document> that contains the added schema, or C<undef >
679
- if the resource could not be found.
680
-
681
- May die with a listref of L<JSON::Schema::Draft201909::Error> object(s), if there were errors in the
682
- document.
684
+ Returns C<undef > if the resource could not be found;
685
+ if there were errors in the document, will die with a L<JSON::Schema::Draft201909::Result> object
686
+ containing the errors;
687
+ otherwise returns the L<JSON::Schema::Draft201909::Document> that contains the added schema.
683
688
684
689
=head2 get
685
690
0 commit comments