From: Sebastian Harl Date: Sat, 17 Nov 2007 17:45:58 +0000 (+0100) Subject: Collectd.pm: Improved error handling of failed callbacks. X-Git-Tag: collectd-4.3.0beta0~91 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c63d52c52bfe891c8faa62e0d5539d7fba7b3d88;p=collectd.git Collectd.pm: Improved error handling of failed callbacks. If call_by_name() failed, it will be handled the same way as if the callback returned "false". The $@ variable may now be used by plugins as well to describe errors in greater detail. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/bindings/perl/Collectd.pm b/bindings/perl/Collectd.pm index 8c3159c7..2de98850 100644 --- a/bindings/perl/Collectd.pm +++ b/bindings/perl/Collectd.pm @@ -143,12 +143,21 @@ sub plugin_call_all { $cb_name = $p->{'cb_name'}; $status = call_by_name (@_); - if (! defined $status) { + if (! $status) { + my $err = undef; + + if ($@) { + $err = $@; + } + else { + $err = "callback returned false"; + } + if (TYPE_LOG != $type) { - ERROR ("Could not execute callback \"$cb_name\": $@"); + ERROR ("Execution of callback \"$cb_name\" failed: $err"); } - next; + $status = 0; } if ($status) { @@ -156,23 +165,23 @@ sub plugin_call_all { $p->{'wait_time'} = 10; } elsif (TYPE_READ == $type) { + WARNING ("${plugin}->read() failed with status $status. " + . "Will suspend it for $p->{'wait_left'} seconds."); + $p->{'wait_left'} = $p->{'wait_time'}; $p->{'wait_time'} *= 2; if ($p->{'wait_time'} > 86400) { $p->{'wait_time'} = 86400; } - - WARNING ("${plugin}->read() failed with status $status. " - . "Will suspend it for $p->{'wait_left'} seconds."); } elsif (TYPE_INIT == $type) { + ERROR ("${plugin}->init() failed with status $status. " + . "Plugin will be disabled."); + foreach my $type (keys %types) { plugin_unregister ($type, $plugin); } - - ERROR ("${plugin}->init() failed with status $status. " - . "Plugin will be disabled."); } elsif (TYPE_LOG != $type) { WARNING ("${plugin}->$types{$type}() failed with status $status."); diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod index 2b776674..73bacc6d 100644 --- a/src/collectd-perl.pod +++ b/src/collectd-perl.pod @@ -103,6 +103,9 @@ be used to clean up the plugin (e.g. close sockets, ...). =back +Any function may set the B<$@> variable to describe errors in more detail. The +message will be passed on to the user using collectd's logging mechanism. + See the documentation of the B method in the section "METHODS" below for the number and types of arguments passed to each B. This section also explains how to register B