From 998cdde4cd089542a163472684063dba67d05694 Mon Sep 17 00:00:00 2001 From: Ioannis Bonatakis Date: Sat, 1 Mar 2025 08:34:44 +0100 Subject: [PATCH] Replace Try::Tiny from remaining OpenQA modules Another patch of the remaining leftover modules which didnt migrated to Feature::Compat::Try. https://progress.opensuse.org/issues/176862 --- .../WebAPI/Controller/API/V1/JobTemplate.pm | 14 ++++++------- lib/OpenQA/WebSockets/Controller/Worker.pm | 21 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/OpenQA/WebAPI/Controller/API/V1/JobTemplate.pm b/lib/OpenQA/WebAPI/Controller/API/V1/JobTemplate.pm index e1b37c4717f..49496cecb77 100644 --- a/lib/OpenQA/WebAPI/Controller/API/V1/JobTemplate.pm +++ b/lib/OpenQA/WebAPI/Controller/API/V1/JobTemplate.pm @@ -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); @@ -251,10 +251,10 @@ 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 = {}; @@ -262,12 +262,12 @@ sub update ($self) { 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'; diff --git a/lib/OpenQA/WebSockets/Controller/Worker.pm b/lib/OpenQA/WebSockets/Controller/Worker.pm index 8bba55305c1..439d8b52373 100644 --- a/lib/OpenQA/WebSockets/Controller/Worker.pm +++ b/lib/OpenQA/WebSockets/Controller/Worker.pm @@ -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; @@ -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; @@ -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 @@ -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; }