diff --git a/CMakeLists.txt b/CMakeLists.txt index 6800a74..762cdbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ if (KDESRC_BUILD_INSTALL_MODULES) message(STATUS "Installing component modules to ${KDESRC_BUILD_MODULE_INSTALL_PREFIX}") install(FILES modules/ksb/BuildContext.pm + modules/ksb/BuildException.pm modules/ksb/BuildSystem.pm modules/ksb/Debug.pm modules/ksb/DependencyResolver.pm diff --git a/kdesrc-build b/kdesrc-build index d6bc3ce..36266d4 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -2999,7 +2999,7 @@ eval if (my $err = $@) { - if (ref $err && $err->isa('BuildException')) { + if (ref $err && $err->isa('ksb::BuildException')) { print $err->{'exception_type'}, " error: ", $err->{'message'}, "\n"; print "\tCan't continue, so stopping now.\n"; diff --git a/kdesrc-build-test.pl b/kdesrc-build-test.pl index 0460c4e..9a7220f 100755 --- a/kdesrc-build-test.pl +++ b/kdesrc-build-test.pl @@ -450,7 +450,7 @@ $@ = ''; eval { @filtered_modules = applyModuleFilters($ctx, @conf_modules); }; -isa_ok($@, 'BuildException', 'resume-{from,after} combine for exception'); +isa_ok($@, 'ksb::BuildException', 'resume-{from,after} combine for exception'); $ctx->deleteOption('resume-from'); @filtered_modules = applyModuleFilters($ctx, @conf_modules); @@ -615,7 +615,7 @@ done_testing(); }; # eval if (my $err = $@) { - if (blessed ($err) && $err->isa('BuildException')) { + if (blessed ($err) && $err->isa('ksb::BuildException')) { say "Test suite failed after kdesrc-build threw the following exception:"; say "$@->{message}"; fail(); diff --git a/modules/ksb/BuildException.pm b/modules/ksb/BuildException.pm new file mode 100644 index 0000000..e6e0a74 --- /dev/null +++ b/modules/ksb/BuildException.pm @@ -0,0 +1,30 @@ +package ksb::BuildException; + +# A class to wrap 'exception' messages for the script, allowing them to be +# dispatch based on type and automatically stringified. + +use v5.10; # Needed for state keyword +use strict; +use warnings; +use overload + '""' => \&to_string; + +our $VERSION = '0.10'; + +sub new +{ + my ($class, $type, $msg) = @_; + + return bless({ + 'exception_type' => $type, + 'message' => $msg, + }, $class); +} + +sub to_string +{ + my $exception = shift; + return $exception->{exception_type} . " Error: " . $exception->{message}; +} + +1; diff --git a/modules/ksb/Module.pm b/modules/ksb/Module.pm index 8b2ccc0..dc36aad 100644 --- a/modules/ksb/Module.pm +++ b/modules/ksb/Module.pm @@ -700,7 +700,7 @@ sub update { my $reason = ksb::IPC::MODULE_FAILURE; - if (ref $@ && $@->isa('BuildException')) { + if (ref $@ && $@->isa('ksb::BuildException')) { if ($@->{'exception_type'} eq 'ConflictPresent') { $reason = ksb::IPC::MODULE_CONFLICT; } diff --git a/modules/ksb/Updater/Svn.pm b/modules/ksb/Updater/Svn.pm index 8ec606c..36f9383 100644 --- a/modules/ksb/Updater/Svn.pm +++ b/modules/ksb/Updater/Svn.pm @@ -666,10 +666,6 @@ sub svnInfo if($@) { - if (ref $@ && $@->isa('BuildException')) { - $@ = $@->{message}; - } - error ("Unable to run r[b[svn], is the Subversion program installed?"); error (" -- Error was: r[$@]"); return undef; diff --git a/modules/ksb/Util.pm b/modules/ksb/Util.pm index d2951c7..2aa025c 100644 --- a/modules/ksb/Util.pm +++ b/modules/ksb/Util.pm @@ -17,6 +17,7 @@ use Digest::MD5; use ksb::Debug; use ksb::Version qw(scriptVersion); +use ksb::BuildException; use Exporter qw(import); # Use Exporter's import method our @EXPORT = qw(list_has make_exception assert_isa assert_in any @@ -62,10 +63,10 @@ sub absPathToExecutable # Returns a Perl object worth "die"ing for. (i.e. can be given to the die # function and handled appropriately later with an eval). The returned -# reference will be an instance of BuildException. The actual exception -# type is passed in as the first parameter (as a string), and can be -# retrieved from the object later using the 'exception_type' key, and the -# message is returned as 'message' +# reference will be an instance of ksb::BuildException. The actual exception +# type is passed in as the first parameter (as a string), and can be retrieved +# from the object later using the 'exception_type' key, and the message is +# returned as 'message' # # First parameter: Exception type. Recommended are one of: Config, Internal # (for logic errors), Runtime (other runtime errors which are not logic @@ -82,10 +83,7 @@ sub make_exception local $Carp::CarpLevel = 1 + $levels; $message = Carp::cluck($message) if $exception_type eq 'Internal'; - return bless({ - 'exception_type' => $exception_type, - 'message' => $message, - }, 'BuildException'); + return ksb::BuildException->new($exception_type, $message); } # Should be used for "runtime errors" (i.e. unrecoverable runtime problems that