Make exception class an actual class.

This is a long-overdue change that allows for overloading the
stringification operator to produce better error messages.
BuildException was previously not an actual module since kdesrc-build
itself was just a single script file. Now that we allow modules on disk
there is no reason to leave the exception class as a figment of Perl's
imagination.
wilder
Michael Pyne 13 years ago
parent d590068f13
commit 56d1e7c21d
  1. 1
      CMakeLists.txt
  2. 2
      kdesrc-build
  3. 4
      kdesrc-build-test.pl
  4. 30
      modules/ksb/BuildException.pm
  5. 2
      modules/ksb/Module.pm
  6. 4
      modules/ksb/Updater/Svn.pm
  7. 14
      modules/ksb/Util.pm

@ -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

@ -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";

@ -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();

@ -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;

@ -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;
}

@ -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;

@ -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

Loading…
Cancel
Save