Skip to content

Commit

Permalink
cleanup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Nov 16, 2024
1 parent 6cb44fc commit 648d571
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/Thruk/Controller/cmd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ sub _bulk_send_backend {
};
my $err = $@;
if($err) {
$err =~ s/(\ at\ .*?\.pm\ line\ \d+).*$//gsmx;
$err = _strip_line($err);
$c->stash->{'last_command_error'} = $err;
Thruk::Utils::set_message($c, 'fail_message', "sending command failed: ".$err);
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/Thruk/Controller/extinfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use Thruk::Backend::Manager ();
use Thruk::UserAgent ();
use Thruk::Utils::Auth ();
use Thruk::Utils::External ();
use Thruk::Utils::Log qw/:all/;
use Thruk::Utils::Status ();

=head1 NAME
Expand Down Expand Up @@ -875,8 +876,7 @@ sub _process_perf_info_page {
$c->stash->{'has_logcache'} = 1;
};
if($@) {
$c->stash->{'logcache_error'} = $@;
$c->stash->{'logcache_error'} =~ s/\ at\ .*?\ line\ \d+\.//gmx;
$c->stash->{'logcache_error'} = _strip_line($@);
}
}

Expand Down
9 changes: 3 additions & 6 deletions lib/Thruk/Controller/status.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Cpanel::JSON::XS qw/decode_json/;
use Thruk::Action::AddDefaults ();
use Thruk::Backend::Manager ();
use Thruk::Utils::Auth ();
use Thruk::Utils::Log qw/:all/;
use Thruk::Utils::Status ();

=head1 NAME
Expand Down Expand Up @@ -1493,9 +1494,7 @@ sub _process_verify_time {
$verified = 1;
}
if($@) {
$error = $@;
chomp($error);
$error =~ s/\ at .*?\.pm\ line\ \d+//gmx;
$error = _strip_line($@);
}
}

Expand All @@ -1509,9 +1508,7 @@ sub _process_verify_time {
$verified = 1;
}
if($@) {
$error = $@;
chomp($error);
$error =~ s/\ at .*?\.pm\ line\ \d+//gmx;
$error = _strip_line($@);
}
}

Expand Down
10 changes: 9 additions & 1 deletion lib/Thruk/Utils/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use Thruk::Utils::Encode ();
use base 'Exporter';
our @EXPORT_OK = qw(_fatal _error _cronerror _warn _info _infos _infoc
_debug _debug2 _debugs _debugc _trace _audit_log
_debug_http_response
_debug_http_response _strip_line
);
our %EXPORT_TAGS = ( all => \@EXPORT_OK );

Expand Down Expand Up @@ -139,6 +139,14 @@ sub _debug_http_response {
return;
}

##############################################
sub _strip_line {
my($error) = @_;
chomp($error);
$error =~ s/\ at\ [a-zA-Z\/\.]+?\ line\ \d+\.$//gmx;
return($error);
}

##############################################
sub _log {
my($lvl, $data, $options) = @_;
Expand Down
3 changes: 1 addition & 2 deletions lib/Thruk/Utils/Status.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ sub do_filter {
my $err = $@;
if($err) {
_debug("lex filter failed: %s", $err);
$err =~ s/\ at\ [a-zA-Z\/\.]+?\ line\ \d+\.$//gmx;
Thruk::Utils::set_message($c, 'fail_message', $err);
Thruk::Utils::set_message($c, 'fail_message', _strip_line($err));
$c->stash->{'has_error'} = 1;
}
if(!$c->stash->{'has_error'} && (!$c->stash->{'minimal'} || $c->stash->{'play_sounds'}) && ( $prefix eq 'dfl_' or $prefix eq 'ovr_' or $prefix eq 'grd_' or $prefix eq '')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ sub _action_facts {
}
if(!$facts || $facts->{'last_error'}) {
my $err = sprintf("%s updating %s failed: %s\n", $peer->{'name'}, $mode, ($facts->{'last_error'}//'unknown error'));
_cronerror($err); # don't fill the log with errors from cronjobs
_cronerror(_strip_line($err)); # don't fill the log with errors from cronjobs
} else {
_info("%s updated %s sucessfully: OK\n", $peer->{'name'}, $mode);
}
Expand Down
2 changes: 1 addition & 1 deletion t/022-Thruk-Utils-Log.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sub check_logger {
return if $content =~ m/\Quse Thruk::Utils::Log\E/gmx;
$content =~ s|::make_info\(||gmx; # reduce false positive
$content =~ s|::http_response_error\(||gmx; # reduce false positive
if($content =~ m/^(.*(_debug|_error|_warn|_info|_audit_log)\(.*)/gmx) {
if($content =~ m/^(.*(_debug|_error|_warn|_info|_audit_log|_strip_line|_cronerror)\(.*)/gmx) {
my $line = $1;
unless($content =~ m/\Quse Thruk::Utils::Log\E/gmx) {
fail($file." uses logger but misses 'use Thruk::Utils::Log'");
Expand Down

0 comments on commit 648d571

Please sign in to comment.