]> git.donarmstrong.com Git - debbugs.git/commitdiff
Add cleanup_eval_fail method to clean up the eval output
authorDon Armstrong <don@donarmstrong.com>
Fri, 19 Jun 2009 16:35:45 +0000 (09:35 -0700)
committerDon Armstrong <don@donarmstrong.com>
Fri, 19 Jun 2009 16:35:45 +0000 (09:35 -0700)
Debbugs/Common.pm
scripts/service

index 2044304f9a6a0e8b003ae561034ec5e3172a123d..d8eaf40b2b336c808ebb12327e8aa25e4df34c3d 100644 (file)
@@ -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;
 
index 035ae819a64c39a7d90d2d82831041b12e669afa..3756625fe1cdaf747a7df60737c0ba93f570adc0 100755 (executable)
@@ -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++;