Skip to content

Commit

Permalink
Avoid changing Perl-global for UTF-8-encoded output in CLI
Browse files Browse the repository at this point in the history
As mentioned in #5036 (review)
this otherwise breaks outputting JSON.
  • Loading branch information
Martchus committed Mar 20, 2023
1 parent 585dc24 commit 82343ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/OpenQA/CLI/schedule.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# SPDX-License-Identifier: GPL-2.0-or-later

package OpenQA::CLI::schedule;
use Encode 'encode_utf8';
use OpenQA::Jobs::Constants;
use Mojo::Base 'OpenQA::Command', -signatures;
use Mojo::Util qw(getopt);
use Term::ANSIColor qw(colored);
use open qw(:std :encoding(UTF-8));

has description => 'Schedules a set of jobs (via "isos post" creating a schedule product)';
has usage => sub { shift->extract_usage };
Expand Down Expand Up @@ -37,7 +37,7 @@ sub _monitor_jobs ($self, $client, $poll_interval, $job_ids, $job_results) {
push @$job_results, $job->{result} // NONE;
next;
}
print "Job state of job ID $job_id: $job_state, waiting …\n";
print encode_utf8("Job state of job ID $job_id: $job_state, waiting …\n");
sleep $poll_interval;
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/OpenQA/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package OpenQA::Command;
use Mojo::Base 'Mojolicious::Command', -signatures;

use Encode 'encode_utf8';
use Cpanel::JSON::XS ();
use OpenQA::Client;
use Mojo::IOLoop;
use Mojo::Util qw(decode getopt);
use Mojo::URL;
use Mojo::File qw(path);
use Term::ANSIColor qw(colored);
use open qw(:std :encoding(UTF-8));

my $JSON = Cpanel::JSON::XS->new->utf8->canonical->allow_nonref->allow_unknown->allow_blessed->convert_blessed
->stringify_infnan->escape_slash->allow_dupkeys->pretty;
Expand Down Expand Up @@ -115,7 +115,8 @@ sub retry_tx ($self, $client, $tx, $handle_args, $retries = undef, $delay = unde
$tx = $client->start($tx);
my $res_code = $tx->res->code // 0;
return $self->handle_result($tx, $handle_args) unless $res_code =~ /50[23]/ && $retries > 0;
print "Request failed, hit error $res_code, retrying up to $retries more times after waiting …\n";
print encode_utf8(
"Request failed, hit error $res_code, retrying up to $retries more times after waiting …\n");
sleep $delay;
}
}
Expand Down

0 comments on commit 82343ca

Please sign in to comment.