From c1ba4f4f50e880799a9a1baf9ab0f976185743dc Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Tue, 14 Apr 2015 18:04:59 +0300 Subject: [PATCH] Bug 13995 - Proper Exception handling try { Koha::Exception::BadSystemPreference->throw(error => 'Syspref DisplayIconsXSLT is not a valid boolean'); } catch { if (blessed($_) && $_->isa('Koha::Exception::BadSystemPreference')) { print $_->as_string(); warn $_->error, "\n", $_->trace->as_string, "\n"; } else { $_->rethrow(); } } --- C4/Installer/PerlDependencies.pm | 5 +++++ Koha/Exception/BadAuthenticationToken.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/BadEncoding.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/BadParameter.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/BadSystemPreference.pm | 29 +++++++++++++++++++++++++++++ Koha/Exception/ConnectionFailed.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/DuplicateObject.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/File.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/LoginFailed.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/NoSystemPreference.pm | 29 +++++++++++++++++++++++++++++ Koha/Exception/RemoteInvocation.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/SystemCall.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/UnknownObject.pm | 28 ++++++++++++++++++++++++++++ Koha/Exception/UnknownProtocol.pm | 28 ++++++++++++++++++++++++++++ 14 files changed, 371 insertions(+) create mode 100644 Koha/Exception/BadAuthenticationToken.pm create mode 100644 Koha/Exception/BadEncoding.pm create mode 100644 Koha/Exception/BadParameter.pm create mode 100644 Koha/Exception/BadSystemPreference.pm create mode 100644 Koha/Exception/ConnectionFailed.pm create mode 100644 Koha/Exception/DuplicateObject.pm create mode 100644 Koha/Exception/File.pm create mode 100644 Koha/Exception/LoginFailed.pm create mode 100644 Koha/Exception/NoSystemPreference.pm create mode 100644 Koha/Exception/RemoteInvocation.pm create mode 100644 Koha/Exception/SystemCall.pm create mode 100644 Koha/Exception/UnknownObject.pm create mode 100644 Koha/Exception/UnknownProtocol.pm diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 2374304..1d2205d 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -99,6 +99,11 @@ our $PERL_DEPS = { 'required' => '1', 'min_ver' => '1.103' }, + 'Exception::Class' => { + 'usage' => 'Core', + 'required' => '1.39', + 'min_ver' => '1.39' + }, 'HTML::Scrubber' => { 'usage' => 'Core', 'required' => '1', diff --git a/Koha/Exception/BadAuthenticationToken.pm b/Koha/Exception/BadAuthenticationToken.pm new file mode 100644 index 0000000..4c63d19 --- /dev/null +++ b/Koha/Exception/BadAuthenticationToken.pm @@ -0,0 +1,28 @@ +package Koha::Exception::BadAuthenticationToken; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::BadAuthenticationToken' => { + description => 'Authentication token is invalid', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/BadEncoding.pm b/Koha/Exception/BadEncoding.pm new file mode 100644 index 0000000..e26142f --- /dev/null +++ b/Koha/Exception/BadEncoding.pm @@ -0,0 +1,28 @@ +package Koha::Exception::BadEncoding; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::BadEncoding' => { + description => 'Something wrong with the character encoding', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/BadParameter.pm b/Koha/Exception/BadParameter.pm new file mode 100644 index 0000000..1c56cf6 --- /dev/null +++ b/Koha/Exception/BadParameter.pm @@ -0,0 +1,28 @@ +package Koha::Exception::BadParameter; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::BadParameter' => { + description => 'Something wrong with the given parameters', + }, +); + +return 1; diff --git a/Koha/Exception/BadSystemPreference.pm b/Koha/Exception/BadSystemPreference.pm new file mode 100644 index 0000000..6d24039 --- /dev/null +++ b/Koha/Exception/BadSystemPreference.pm @@ -0,0 +1,29 @@ +package Koha::Exception::BadSystemPreference; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::BadSystemPreference' => { + description => 'System preference value is incomprehensible', + fields => ['syspref'], + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/ConnectionFailed.pm b/Koha/Exception/ConnectionFailed.pm new file mode 100644 index 0000000..1c35949 --- /dev/null +++ b/Koha/Exception/ConnectionFailed.pm @@ -0,0 +1,28 @@ +package Koha::Exception::ConnectionFailed; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::ConnectionFailed' => { + description => 'Connecting to host failed', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/DuplicateObject.pm b/Koha/Exception/DuplicateObject.pm new file mode 100644 index 0000000..d796cbe --- /dev/null +++ b/Koha/Exception/DuplicateObject.pm @@ -0,0 +1,28 @@ +package Koha::Exception::DuplicateObject; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::DuplicateObject' => { + description => 'Same object already exists', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/File.pm b/Koha/Exception/File.pm new file mode 100644 index 0000000..aa4cb98 --- /dev/null +++ b/Koha/Exception/File.pm @@ -0,0 +1,28 @@ +package Koha::Exception::File; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::File' => { + description => 'Something wrong with the given file', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/LoginFailed.pm b/Koha/Exception/LoginFailed.pm new file mode 100644 index 0000000..561d5c3 --- /dev/null +++ b/Koha/Exception/LoginFailed.pm @@ -0,0 +1,28 @@ +package Koha::Exception::LoginFailed; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::LoginFailed' => { + description => 'Login to host failed', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/NoSystemPreference.pm b/Koha/Exception/NoSystemPreference.pm new file mode 100644 index 0000000..ad6f0b8 --- /dev/null +++ b/Koha/Exception/NoSystemPreference.pm @@ -0,0 +1,29 @@ +package Koha::Exception::NoSystemPreference; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::NoSystemPreference' => { + description => 'Required system preference is not set', + fields => ['syspref'], + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/RemoteInvocation.pm b/Koha/Exception/RemoteInvocation.pm new file mode 100644 index 0000000..bca3c0b --- /dev/null +++ b/Koha/Exception/RemoteInvocation.pm @@ -0,0 +1,28 @@ +package Koha::Exception::RemoteInvocation; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::RemoteInvocation' => { + description => 'Interacting with a remote process failed', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/SystemCall.pm b/Koha/Exception/SystemCall.pm new file mode 100644 index 0000000..35dfe18 --- /dev/null +++ b/Koha/Exception/SystemCall.pm @@ -0,0 +1,28 @@ +package Koha::Exception::SystemCall; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::SystemCall' => { + description => 'Making a system call failed', + }, +); + +return 1; \ No newline at end of file diff --git a/Koha/Exception/UnknownObject.pm b/Koha/Exception/UnknownObject.pm new file mode 100644 index 0000000..2647f5a --- /dev/null +++ b/Koha/Exception/UnknownObject.pm @@ -0,0 +1,28 @@ +package Koha::Exception::UnknownObject; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::UnknownObject' => { + description => 'Object cannot be found or is not known', + }, +); + +return 1; diff --git a/Koha/Exception/UnknownProtocol.pm b/Koha/Exception/UnknownProtocol.pm new file mode 100644 index 0000000..0365f2e --- /dev/null +++ b/Koha/Exception/UnknownProtocol.pm @@ -0,0 +1,28 @@ +package Koha::Exception::UnknownProtocol; + +# Copyright 2015 Vaara-kirjastot +# +# This file is part of Koha. +# +# Koha 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. +# +# Koha 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. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Exception::Class ( + 'Koha::Exception::UnknownProtocol' => { + description => 'Protocol is not known', + }, +); + +return 1; \ No newline at end of file -- 1.7.9.5