Skip to content

Commit

Permalink
containers: Fix issue with failing decode_json() in engine->info()
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Dec 30, 2024
1 parent 1e21e2b commit 10cb010
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/containers/engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Otherwise it prints the output of info.
sub info {
my ($self, %args) = @_;
my $stdout;
my $json_error = "";

if (exists $args{json} && $args{json}) {
my $raw = $self->_engine_script_output("info -f '{{json .}}' 2> ./error", proceed_on_failure => 1);
Expand All @@ -227,7 +228,12 @@ sub info {
if ($raw =~ m/(?s)(\{(?:[^{}"]++|"(?:\\.|[^"])*+"|(?1))*\})/gm) {
$raw = $1;
}
$stdout = decode_json($raw);
eval {
$stdout = decode_json($raw);
};
if ($@) {
$json_error = $@;
}
} else {
$stdout = $self->_engine_script_output("info 2> ./error", proceed_on_failure => 1);
}
Expand All @@ -240,6 +246,8 @@ sub info {
}
}

die "Error decoding JSON: $json_error for $raw" if $json_error;

return $stdout;
}

Expand Down

0 comments on commit 10cb010

Please sign in to comment.