gecko-dev/webtools/litmus/Litmus/Error.pm
2006-08-01 20:50:15 +00:00

85 lines
2.0 KiB
Perl
Executable File

# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-
=head1 COPYRIGHT
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License
# at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and
# limitations under the License.
#
# The Original Code is Litmus.
#
# The Initial Developer of the Original Code is
# the Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Chris Cooper <ccooper@deadsquid.com>
# Zach Lipton <zach@zachlipton.com>
#
# ***** END LICENSE BLOCK *****
=cut
# General error reporting
package Litmus::Error;
use strict;
our @ISA = qw(Exporter);
@Litmus::Error::EXPORT = qw(
basicError
invalidInputError
internalError
lastDitchError
);
# just a general run of the mill error
sub basicError {
my $message = shift;
_doError($message);
exit;
}
# used to alert the user when an unexpected input value is found
sub invalidInputError($) {
my $message = shift;
_doError("Invalid Input - $message");
exit;
}
sub internalError($) {
my $message = shift;
_doError("Litmus has suffered an internal error - $message");
exit;
}
# an error type that does not use a template error message. Used if we
# can't even process the error template.
sub lastDitchError($) {
my $message = shift;
print "Error - Litmus has suffered a serious fatal internal error - $message";
exit;
}
sub _doError($) {
my $message = shift;
my $vars = {
message => $message,
};
Litmus->template()->process("error/error.html.tmpl", $vars) ||
lastDitchError(Litmus->template()->error());
}
1;