From 0b780ffb90da061e2a75549bb471e15eb7a59630 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Fri, 1 Jan 2021 18:00:59 +0100 Subject: [PATCH] CTR: Benutzereingabe in data mit Try::Tiny auffangen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Sinnvolle Fehlermeldung in einem Satz zurückgeben und danach den kompletten Trace. --- SL/BackgroundJob/ConvertTimeRecordings.pm | 11 +++++++++-- SL/InstallationCheck.pm | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/SL/BackgroundJob/ConvertTimeRecordings.pm b/SL/BackgroundJob/ConvertTimeRecordings.pm index 6af9ae94a..810d9bccc 100644 --- a/SL/BackgroundJob/ConvertTimeRecordings.pm +++ b/SL/BackgroundJob/ConvertTimeRecordings.pm @@ -8,7 +8,9 @@ use SL::DB::DeliveryOrder; use SL::DB::TimeRecording; use SL::Locale::String qw(t8); + use DateTime; +use Try::Tiny; sub create_job { $_[0]->create_standard_job('7 3 1 * *'); # every first day of month at 03:07 @@ -31,8 +33,13 @@ sub run { # from/to date from data. Defaults to begining and end of last month. my $from_date; my $to_date; - $from_date = DateTime->from_kivitendo($data->{from_date}) if $data->{from_date}; - $to_date = DateTime->from_kivitendo($data->{to_date}) if $data->{to_date}; + # handle errors with a catch handler + try { + $from_date = DateTime->from_kivitendo($data->{from_date}) if $data->{from_date}; + $to_date = DateTime->from_kivitendo($data->{to_date}) if $data->{to_date}; + } catch { + die "Cannot convert date from string $data->{from_date} $data->{to_date}\n Details :\n $_"; # not $@ + }; $from_date ||= DateTime->new( day => 1, month => DateTime->today_local->month, year => DateTime->today_local->year)->subtract(months => 1); $to_date ||= DateTime->last_day_of_month(month => DateTime->today_local->month, year => DateTime->today_local->year)->subtract(months => 1); diff --git a/SL/InstallationCheck.pm b/SL/InstallationCheck.pm index aeac4e59d..5ac4adf22 100644 --- a/SL/InstallationCheck.pm +++ b/SL/InstallationCheck.pm @@ -62,6 +62,7 @@ BEGIN { { name => "Text::CSV_XS", version => '0.23', url => "http://search.cpan.org/~hmbrand/", debian => 'libtext-csv-xs-perl' }, { name => "Text::Iconv", version => '1.2', url => "http://search.cpan.org/~mpiotr/", debian => 'libtext-iconv-perl' }, { name => "Text::Unidecode", url => "http://search.cpan.org/~sburke/", debian => 'libtext-unidecode-perl' }, + { name => "Try::Tiny", url => "https://metacpan.org/release/Try-Tiny", debian => 'libtry-tiny-perl' }, { name => "URI", version => '1.35', url => "http://search.cpan.org/~gaas/", debian => 'liburi-perl' }, { name => "XML::LibXML", url => "https://metacpan.org/pod/XML::LibXML", debian => 'libxml-libxml-perl' }, { name => "XML::Writer", version => '0.602', url => "http://search.cpan.org/~josephw/", debian => 'libxml-writer-perl' }, -- 2.20.1