Skip to content

Commit

Permalink
Replace Try::Tiny from remaining OpenQA modules
Browse files Browse the repository at this point in the history
Another patch of the remaining leftover modules which didnt migrated to
Feature::Compat::Try.

https://progress.opensuse.org/issues/176862
  • Loading branch information
b10n1k committed Feb 28, 2025
1 parent 191b00b commit 63478e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
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
20 changes: 10 additions & 10 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 @@ -168,9 +168,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
Expand All @@ -183,10 +183,10 @@ sub _message ($self, $json) {
log_debug("Rescheduling jobs assigned to worker $worker_id");
$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}
Expand Down

0 comments on commit 63478e0

Please sign in to comment.