diff --git a/lib/containers/engine.pm b/lib/containers/engine.pm index 68cfc2cc3ffb..28c628b057ea 100644 --- a/lib/containers/engine.pm +++ b/lib/containers/engine.pm @@ -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); @@ -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); } @@ -240,6 +246,8 @@ sub info { } } + die "Error decoding JSON: $json_error for $raw" if $json_error; + return $stdout; }