From b4948c8ff1fe73b3ff292ee1fe344a53071b425a Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Fri, 19 Jun 2009 09:35:45 -0700 Subject: [PATCH] Add cleanup_eval_fail method to clean up the eval output --- Debbugs/Common.pm | 40 +++++++++++++++++++++++++++++++++++++++- scripts/service | 36 ++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/Debbugs/Common.pm b/Debbugs/Common.pm index 2044304..d8eaf40 100644 --- a/Debbugs/Common.pm +++ b/Debbugs/Common.pm @@ -44,7 +44,9 @@ BEGIN{ qw(getmaintainers_reverse), qw(getpseudodesc), ], - misc => [qw(make_list globify_scalar english_join checkpid)], + misc => [qw(make_list globify_scalar english_join checkpid), + qw(cleanup_eval_fail), + ], date => [qw(secs_to_english)], quit => [qw(quit)], lock => [qw(filelock unfilelock lockpid)], @@ -615,6 +617,42 @@ sub globify_scalar { return IO::File->new('/dev/null','w'); } +=head2 cleanup_eval_fail() + + print "Something failed with: ".cleanup_eval_fail($@); + +Does various bits of cleanup on the failure message from an eval (or +any other die message) + +Takes at most two options; the first is the actual failure message +(usually $@ and defaults to $@), the second is the debug level +(defaults to $DEBUG). + +If debug is non-zero, the code at which the failure occured is output. + +=cut + +sub cleanup_eval_fail { + my ($error,$debug) = @_; + if (not defined $error or not @_) { + $error = $@ || 'unknown reason'; + } + if (@_ <= 1) { + $debug = $DEBUG || 0; + } + $debug = 0 if not defined $debug; + + if ($debug > 0) { + return $error; + } + # ditch the "at foo/bar/baz.pm line 5" + $error =~ s/\sat\s\S+\sline\s\d+//; + # ditch trailing multiple periods in case there was a cascade of + # die messages. + $error =~ s/\.+$/\./; + return $error; +} + 1; diff --git a/scripts/service b/scripts/service index 035ae81..3756625 100755 --- a/scripts/service +++ b/scripts/service @@ -562,7 +562,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to clear fixed versions and reopen on $ref: $@"; + print {$transcript} "Failed to clear fixed versions and reopen on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^reopen\s+\#?(-?\d+)(?:\s+([\=\!]|(?:\S.*\S)))?$/i) { $ok++; @@ -585,7 +585,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to reopen $ref: $@"; + print {$transcript} "Failed to reopen $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m{^(?:(?i)found)\s+\#?(-?\d+) (?:\s+((?:$config{package_name_re}\/)? @@ -609,7 +609,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to add found on $ref: $@"; + print {$transcript} "Failed to add found on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } else { @@ -622,7 +622,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to clear fixed versions and reopen on $ref: $@"; + print {$transcript} "Failed to clear fixed versions and reopen on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } } @@ -647,7 +647,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to remove found on $ref: $@"; + print {$transcript} "Failed to remove found on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m{^(?:(?i)fixed)\s+\#?(-?\d+) @@ -671,7 +671,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to add fixed on $ref: $@"; + print {$transcript} "Failed to add fixed on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m{^(?:(?i)notfixed)\s+\#?(-?\d+) @@ -695,7 +695,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to remove fixed on $ref: $@"; + print {$transcript} "Failed to remove fixed on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^submitter\s+\#?(-?\d+)\s+(\!|\S.*\S)$/i) { @@ -717,7 +717,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to set submitter on $ref: $@"; + print {$transcript} "Failed to set submitter on $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } } elsif (m/^forwarded\s+\#?(-?\d+)\s+(\S.*\S)$/i) { @@ -734,7 +734,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to set the forwarded-to-address of $ref: $@"; + print {$transcript} "Failed to set the forwarded-to-address of $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^notforwarded\s+\#?(-?\d+)$/i) { $ok++; @@ -749,7 +749,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to clear the forwarded-to-address of $ref: $@"; + print {$transcript} "Failed to clear the forwarded-to-address of $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^(?:severity|priority)\s+\#?(-?\d+)\s+([-0-9a-z]+)$/i) { $ok++; @@ -775,7 +775,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to set severity of $config{bug} $ref to $newseverity: $@"; + print {$transcript} "Failed to set severity of $config{bug} $ref to $newseverity: ".cleanup_eval_fail($@,$debug)."\n"; } } } elsif (m/^tags?\s+\#?(-?\d+)\s+(([=+-])\s*)?(\S.*)?$/i) { @@ -820,7 +820,7 @@ END # we intentionally have two errors here if there is a bad # tag and the above fails for some reason $errors++; - print {$transcript} "Failed to alter tags of $config{bug} $ref: $@"; + print {$transcript} "Failed to alter tags of $config{bug} $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^(un)?block\s+\#?(-?\d+)\s+(?:by|with)\s+(\S.*)?$/i) { $ok++; @@ -838,7 +838,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to set blocking bugs of $ref: $@"; + print {$transcript} "Failed to set blocking bugs of $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^retitle\s+\#?(-?\d+)\s+(\S.*\S)\s*$/i) { $ok++; @@ -853,7 +853,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to set the title of $ref: $@"; + print {$transcript} "Failed to set the title of $ref: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^unmerge\s+\#?(-?\d+)$/i) { $ok++; @@ -1133,7 +1133,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to mark $ref as affecting package(s): $@"; + print {$transcript} "Failed to mark $ref as affecting package(s): ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^summary\s+\#?(-?\d+)\s*(\d+|)\s*$/i) { @@ -1150,7 +1150,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to give $ref a summary: $@"; + print {$transcript} "Failed to give $ref a summary: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^owner\s+\#?(-?\d+)\s+((?:\S.*\S)|\!)\s*$/i) { @@ -1170,7 +1170,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to mark $ref as having an owner: $@"; + print {$transcript} "Failed to mark $ref as having an owner: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^noowner\s+\#?(-?\d+)\s*$/i) { $ok++; @@ -1185,7 +1185,7 @@ END }; if ($@) { $errors++; - print {$transcript} "Failed to mark $ref as not having an owner: $@"; + print {$transcript} "Failed to mark $ref as not having an owner: ".cleanup_eval_fail($@,$debug)."\n"; } } elsif (m/^unarchive\s+#?(\d+)$/i) { $ok++; -- 2.39.2