[pve-devel] [RFC pve-common] improve error handling.

Wolfgang Link w.link at proxmox.com
Mon May 22 10:03:05 CEST 2017


Get more information about the function where a timeout occurs.
---
 src/PVE/Tools.pm | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index f84855d..d3034de 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -88,7 +88,18 @@ use constant {O_PATH    => 0x00200000,
 sub run_with_timeout {
     my ($timeout, $code, @param) = @_;
 
-    die "got timeout\n" if $timeout <= 0;
+    # We need more information if a timeout occurs.
+    my $packname = __PACKAGE__;
+    my $func = (caller(2))[3];
+    my $line = (caller(2))[2];
+
+    # if the caller is in this package we get no real information about it.
+    if ($func =~ m/\Q$packname\E/) {
+	$func = (caller(3))[3];
+	$line = (caller(3))[2];
+    }
+
+    die "got timeout: $func, $line" if $timeout <= 0;
 
     my $prev_alarm = alarm 0; # suspend outer alarm early
 
@@ -117,7 +128,7 @@ sub run_with_timeout {
     # this shouldn't happen anymore?
     die "unknown error" if $sigcount && !$err; # seems to happen sometimes
 
-    die $err if $err;
+    die "$err: $func, $line" if $err;
 
     return $res;
 }
-- 
2.1.4





More information about the pve-devel mailing list