Un bug étrange et intermittent apparaît avec ce code:
my $res = $ua->get($u);
if ($res->is_success and $res->code == 200) {
my $data = $res->content;
my $struct = XMLin($data);
if ($struct->{responseHeader}{status} == 0) {
$results = $struct;
$return = 1;
last;
} else {
warn "\nXML error (try $try): ", $res->status_line, "\n";
sleep 1;
}
} else {
warn "\nRequest error (try $try): ", $res->status_line, , " ", $res->code, "\n";
sleep 1;
}
La line "my $struct = XMLin($data);" génère parfois cette erreur: «File does not exist: at /home/voyage/voyageforum.com/www/admin/Plugins/Solr/SolrSelect.pm line 211».
J'ai ajouté des logs au code avec la fonction eval:
if ($res->is_success and $res->code == 200) {
my $data = $res->content;
my $struct;
eval {
$struct = XMLin($data);
};
if ($@) { # Check if there was an error with XMLin
warn "\nXML parsing error: $@ (try $try)\n";
# Log the content of $data and $res to a file
my $logfile = '/var/www/vhosts/voyageforum.com/solr_error_xml.txt';
my $fh = IO::File->new(">> $logfile");
if (defined $fh) {
print $fh "Error on try $try:\n";
print $fh "Content of \$data:\n$data\n";
print $fh "Content of \$res:\n", Dumper($res), "\n";
print $fh "=========================\n";
$fh->close;
} else {
warn "Failed to open log file: $logfile\n";
}
sleep 1;
} elsif ($struct->{responseHeader}{status} == 0) {
$results = $struct;
$return = 1;
last;
} else {
warn "\nXML error (try $try): ", $res->status_line, "\n";
sleep 1;
}
} else {
warn "\nRequest error (try $try): ", $res->status_line, " ", $res->code, "\n";
sleep 1;
}
En attente que le bug se reproduise pour voir les nouveaux logs et la cause du problème. Curieusement, depuis l'ajout de "eval", le bug n'est pas revenu. À surveiller.
Original post










