Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Try::Tiny from remaining OpenQA modules #6228

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/OpenQA/WebAPI/Controller/API/V1/JobTemplate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package OpenQA::WebAPI::Controller::API::V1::JobTemplate;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use Try::Tiny;
use Feature::Compat::Try;
use OpenQA::App;
use OpenQA::YAML qw(load_yaml dump_yaml);
use List::Util qw(min);
Expand Down Expand Up @@ -251,23 +251,23 @@ sub update ($self) {
$user_errors
= $self->app->validate_yaml($data, $validation->param('schema'), $self->app->log->level eq 'debug');
}
catch {
catch ($e) {
# Push the exception to the list of errors without the trailing new line
push @$user_errors, substr($_, 0, -1);
};
push @$user_errors, substr($e, 0, -1);
}
return $self->respond_to(json => {json => {error => $user_errors}, status => 400}) if @$user_errors;

my $json = {};
my @server_errors;
try {
$self->_perform_update($id, $name, $json, $data, $yaml, $template_reference, $to_expand, $user_errors);
}
catch {
catch ($e) {
# Push the exception to the list of errors without the trailing new line
my $error = substr($_, 0, -1);
my $error = substr($e, 0, -1);
my $error_type = ($error =~ qr/unique constraint/) ? $user_errors : \@server_errors;
push @$error_type, $error unless $error eq 'abort transaction';
};
}

if (@server_errors) {
push @$user_errors, 'Internal server error occurred';
Expand Down
21 changes: 10 additions & 11 deletions lib/OpenQA/WebSockets/Controller/Worker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use OpenQA::Jobs::Constants;
use OpenQA::Scheduler::Client;
use DateTime;
use Data::Dump 'pp';
use Try::Tiny;
use Feature::Compat::Try;
use Mojo::Util 'dumper';

use constant LOG_WORKER_STATUS_MESSAGES => $ENV{OPENQA_LOG_WORKER_STATUS_MESSAGES} // 0;
Expand Down Expand Up @@ -105,10 +105,10 @@ sub _message ($self, $json) {
$_->reschedule_state for @jobs;
});
}
catch {
catch ($e) {
# uncoverable statement
log_warning("Unable to re-schedule job(s) $job_ids_str rejected by worker $worker_id: $_");
};
log_warning("Unable to re-schedule job(s) $job_ids_str rejected by worker $worker_id: $e");
}

# log that we 'saw' the worker
$worker_db->seen;
Expand Down Expand Up @@ -167,9 +167,9 @@ sub _message ($self, $json) {
# Tell the worker that we saw it (used for tests and debugging)
$tx->send({json => {type => 'info', seen => 1}});
}
catch {
log_error("Failed updating seen and error status of worker $worker_id: $_"); # uncoverable statement
};
catch ($e) {
log_error("Failed updating seen and error status of worker $worker_id: $e"); # uncoverable statement
}

# find the job currently associated with that worker and check whether the worker still
# executes the job it is supposed to
Expand Down Expand Up @@ -206,11 +206,10 @@ sub _message ($self, $json) {
$worker->reschedule_assigned_jobs([$current_job, @unfinished_jobs]);
}
}
catch {
catch ($e) {
# uncoverable statement
log_warning("Unable to verify whether worker $worker_id runs its job(s) as expected: $_");
};

log_warning("Unable to verify whether worker $worker_id runs its job(s) as expected: $e");
}
# consider the worker idle unless it claims to be broken or work on a job
$worker_status->{idle_despite_job_assignment} = !$worker_is_broken && !defined $job_id;
}
Expand Down