diff options
Diffstat (limited to 'Bugzilla/Install/Util.pm')
-rw-r--r-- | Bugzilla/Install/Util.pm | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Bugzilla/Install/Util.pm b/Bugzilla/Install/Util.pm index 6621a7a41..7bafa9330 100644 --- a/Bugzilla/Install/Util.pm +++ b/Bugzilla/Install/Util.pm @@ -32,6 +32,7 @@ use File::Basename; use POSIX qw(setlocale LC_CTYPE); use Safe; use Scalar::Util qw(tainted); +use Term::ANSIColor qw(colored); use base qw(Exporter); our @EXPORT_OK = qw( @@ -559,9 +560,25 @@ sub get_console_locale { sub init_console { eval { ON_WINDOWS && require Win32::Console::ANSI; }; $ENV{'ANSI_COLORS_DISABLED'} = 1 if ($@ || !-t *STDOUT); + $SIG{__DIE__} = \&_console_die; prevent_windows_dialog_boxes(); } +sub _console_die { + my ($message) = @_; + # $^S means "we are in an eval" + if ($^S) { + die $message; + } + # Remove newlines from the message before we color it, and then + # add them back in on display. Otherwise the ANSI escape code + # for resetting the color comes after the newline, and Perl thinks + # that it should put "at Bugzilla/Install.pm line 1234" after the + # message. + $message =~ s/\n+$//; + die colored($message, COLOR_ERROR) . "\n"; +} + sub prevent_windows_dialog_boxes { # This code comes from http://bugs.activestate.com/show_bug.cgi?id=82183 # and prevents Perl modules from popping up dialog boxes, particularly |