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 9eb5047 commit 3e9417e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/OpenQA/CLI/schedule.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
package OpenQA::CLI::schedule;
use OpenQA::Jobs::Constants;
use Mojo::Base 'OpenQA::Command', -signatures;
use Mojo::Util qw(getopt);
use Mojo::Util qw(encode 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 +36,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('UTF-8', "Job state of job ID $job_id: $job_state, waiting …\n");
sleep $poll_interval;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/OpenQA/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use Mojo::Base 'Mojolicious::Command', -signatures;
use Cpanel::JSON::XS ();
use OpenQA::Client;
use Mojo::IOLoop;
use Mojo::Util qw(decode getopt);
use Mojo::Util qw(encode 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 +114,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('UTF-8',
"Request failed, hit error $res_code, retrying up to $retries more times after waiting …\n");
sleep $delay;
}
}
Expand Down

0 comments on commit 3e9417e

Please sign in to comment.