Skip to content

Commit

Permalink
Item14237: Split exceptions into individual modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Oct 10, 2017
1 parent f9a7e65 commit dbe4052
Show file tree
Hide file tree
Showing 16 changed files with 737 additions and 327 deletions.
393 changes: 71 additions & 322 deletions core/lib/Foswiki/Exception.pm

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions core/lib/Foswiki/Exception/ASSERT.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See bottom of file for license and copyright information

=begin TML
---+!! Class Foswiki::Exception::ASSERT
This class is only for distinguishing ASSERT-generated exceptions.
=cut

package Foswiki::Exception::ASSERT;
use Foswiki::Class;
extends qw<Foswiki::Exception::Fatal>;

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
8 changes: 3 additions & 5 deletions core/lib/Foswiki/Exception/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use Foswiki::Exception;
package Foswiki::Exception::Config::NoNextDef;

use Foswiki::Class;
extends qw(Foswiki::Exception::Harmless);
extends qw<Foswiki::Exception>;
with qw<Foswiki::Exception::Harmless>;

# Role to prefix exception text with source file info.
package Foswiki::Exception::Config::SrcFile;
Expand Down Expand Up @@ -88,10 +89,7 @@ around stringify => sub {
. $sourceInfo . ")"
: '';

return
$this->stringifyText( $this->text )
. $sectionInfo
. $this->stringifyPostfix;
return $this->stringifyText . $sectionInfo . $this->stringifyPostfix;
};

sub prepareSection {
Expand Down
33 changes: 33 additions & 0 deletions core/lib/Foswiki/Exception/Deadly.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See bottom of file for license and copyright information

=begin TML
---+!! Role Foswiki::Exception::Deadly
As the name implies, exceptions with this role must result in application
failure.
=cut

package Foswiki::Exception::Deadly;
use Moo::Role;

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
47 changes: 47 additions & 0 deletions core/lib/Foswiki/Exception/Engine.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# See bottom of file for license and copyright information

=begin TML
---+!! Class Foswiki::Exception::Engine
Descendant of =%PERLDOC{"Foswiki::Exception::HTTPError"}%=.
=cut

package Foswiki::Exception::Engine;
use Foswiki::Class;
extends qw<Foswiki::Exception::HTTPError>;

around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
my %params = @_;

$params{status} //= 500;
$params{header} //= 'Internal Server Error';

# Simulate the old Foswiki::EngineException behavior.
$params{text} //= $params{response}
if defined $params{response};

return $orig->( $class, %params );
};

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
71 changes: 71 additions & 0 deletions core/lib/Foswiki/Exception/Ext.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# See bottom of file for license and copyright information

=begin TML
---+!! Class Foswiki::Exception::Ext
Base class for Foswiki::ExtManager-related exceptions.
Generic. Must not be used directly.
=cut

package Foswiki::Exception::Ext;

use Foswiki::Class;
extends qw<Foswiki::Exception>;

=begin TML
---+++ ObjectAttribute extension => string
Extension name.
=cut

has extension => (
is => 'ro',
predicate => 1,

# Coerce a ref into class name.
coerce => sub { ref( $_[0] ) // $_[0] },
);

around prepareText => sub {
my $orig = shift;
my $this = shift;

return $this->has_extension
? "Reported extension: " . $this->extension
: "No reported extension";
};

# Preload exceptions
#use Foswiki::Exception::Ext::BadName;
#use Foswiki::Exception::Ext::Load;

END {
use Foswiki;
for my $m (qw<BadName Load Last Restart>) {
Foswiki::load_class("Foswiki::Exception::Ext::$m");
}
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
33 changes: 33 additions & 0 deletions core/lib/Foswiki/Exception/Ext/BadName.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See bottom of file for license and copyright information

package Foswiki::Exception::Ext::BadName;
use Foswiki::Class;
extends qw<Foswiki::Exception::Ext>;
with qw<Foswiki::Exception::Deadly>;

around prepareText => sub {
my $orig = shift;
my $this = shift;

return "Bad extension name: '" . $this->extension . "'";
};

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
39 changes: 39 additions & 0 deletions core/lib/Foswiki/Exception/Ext/Flow.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See bottom of file for license and copyright information

package Foswiki::Exception::Ext::Flow;

=begin TML
---+!! Class Foswiki::Exception::Ext::Flow
Base class of extension flow control events. Pure virtual, makes no sense on its
own.
=cut

use Foswiki::Exception::Ext::Last;
use Foswiki::Exception::Ext::Restart;

use Foswiki::Class;
extends qw<Foswiki::Exception::Ext>;
with qw<Foswiki::Exception::Harmless>;

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
46 changes: 46 additions & 0 deletions core/lib/Foswiki/Exception/Ext/Last.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# See bottom of file for license and copyright information

package Foswiki::Exception::Ext::Last;

=begin TML
---+!! Class Foswiki::Exception::Ext::Last
Subclass of =Foswiki::Exception::Ext::Flow=.
Inidicates that an extension is requesting to be the last in the execution line.
=cut

use Foswiki::Class;
extends qw<Foswiki::Exception::Ext::Flow>;

=begin TML
---++ ObjectAttribute rc
Return value of a method call.
=cut

has rc => ( is => 'rw', predicate => 1, );

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
40 changes: 40 additions & 0 deletions core/lib/Foswiki/Exception/Ext/Load.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See bottom of file for license and copyright information

package Foswiki::Exception::Ext::Load;
use Foswiki::Class;
extends qw(Foswiki::Exception::Ext);

has reason => (
is => 'rw',
required => 1,
);

around prepareText => sub {
my $orig = shift;
my $this = shift;

return
"Failed to load extension '"
. $this->extension . "': "
. $this->reason;
};

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2017 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
Loading

0 comments on commit dbe4052

Please sign in to comment.