2015-08-29 20:20:46 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# COMMON EXCEPTION MODULE
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRest::Common::Exception;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess longmess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Exception codes
|
|
|
|
####################################################################################################################################
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_MINIMUM => 100;
|
|
|
|
push @EXPORT, qw(ERROR_MINIMUM);
|
|
|
|
use constant ERROR_MAXIMUM => 199;
|
|
|
|
push @EXPORT, qw(ERROR_MAXIMUM);
|
|
|
|
|
|
|
|
use constant ERROR_ASSERT => ERROR_MINIMUM;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_ASSERT);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_CHECKSUM => ERROR_MINIMUM + 1;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_CHECKSUM);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_CONFIG => ERROR_MINIMUM + 2;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_CONFIG);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FILE_INVALID => ERROR_MINIMUM + 3;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FILE_INVALID);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FORMAT => ERROR_MINIMUM + 4;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FORMAT);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_COMMAND_REQUIRED => ERROR_MINIMUM + 5;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_COMMAND_REQUIRED);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_INVALID => ERROR_MINIMUM + 6;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_INVALID);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_INVALID_VALUE => ERROR_MINIMUM + 7;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_INVALID_VALUE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_INVALID_RANGE => ERROR_MINIMUM + 8;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_INVALID_RANGE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_INVALID_PAIR => ERROR_MINIMUM + 9;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_INVALID_PAIR);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_DUPLICATE_KEY => ERROR_MINIMUM + 10;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_DUPLICATE_KEY);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_NEGATE => ERROR_MINIMUM + 11;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_NEGATE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_OPTION_REQUIRED => ERROR_MINIMUM + 12;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_OPTION_REQUIRED);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_POSTMASTER_RUNNING => ERROR_MINIMUM + 13;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_POSTMASTER_RUNNING);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_PROTOCOL => ERROR_MINIMUM + 14;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_PROTOCOL);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_RESTORE_PATH_NOT_EMPTY => ERROR_MINIMUM + 15;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_RESTORE_PATH_NOT_EMPTY);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FILE_OPEN => ERROR_MINIMUM + 16;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FILE_OPEN);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FILE_READ => ERROR_MINIMUM + 17;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FILE_READ);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_PARAM_REQUIRED => ERROR_MINIMUM + 18;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_PARAM_REQUIRED);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_ARCHIVE_MISMATCH => ERROR_MINIMUM + 19;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_ARCHIVE_MISMATCH);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_ARCHIVE_DUPLICATE => ERROR_MINIMUM + 20;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_ARCHIVE_DUPLICATE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_VERSION_NOT_SUPPORTED => ERROR_MINIMUM + 21;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_VERSION_NOT_SUPPORTED);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_PATH_CREATE => ERROR_MINIMUM + 22;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_PATH_CREATE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_COMMAND_INVALID => ERROR_MINIMUM + 23;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_COMMAND_INVALID);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_HOST_CONNECT => ERROR_MINIMUM + 24;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_HOST_CONNECT);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_LOCK_ACQUIRE => ERROR_MINIMUM + 25;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_LOCK_ACQUIRE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_BACKUP_MISMATCH => ERROR_MINIMUM + 26;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_BACKUP_MISMATCH);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FILE_SYNC => ERROR_MINIMUM + 27;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FILE_SYNC);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_PATH_OPEN => ERROR_MINIMUM + 28;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_PATH_OPEN);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_PATH_SYNC => ERROR_MINIMUM + 29;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_PATH_SYNC);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FILE_MISSING => ERROR_MINIMUM + 30;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FILE_MISSING);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_DB_CONNECT => ERROR_MINIMUM + 31;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_DB_CONNECT);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_DB_QUERY => ERROR_MINIMUM + 32;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_DB_QUERY);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_DB_MISMATCH => ERROR_MINIMUM + 33;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_DB_MISMATCH);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_DB_TIMEOUT => ERROR_MINIMUM + 34;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_DB_TIMEOUT);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_FILE_REMOVE => ERROR_MINIMUM + 35;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_FILE_REMOVE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_PATH_REMOVE => ERROR_MINIMUM + 36;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_PATH_REMOVE);
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_STOP => ERROR_MINIMUM + 37;
|
|
|
|
push @EXPORT, qw(ERROR_STOP);
|
|
|
|
use constant ERROR_TERM => ERROR_MINIMUM + 38;
|
|
|
|
push @EXPORT, qw(ERROR_TERM);
|
|
|
|
use constant ERROR_FILE_WRITE => ERROR_MINIMUM + 39;
|
|
|
|
push @EXPORT, qw(ERROR_FILE_WRITE);
|
|
|
|
use constant ERROR_UNHANDLED_EXCEPTION => ERROR_MINIMUM + 40;
|
|
|
|
push @EXPORT, qw(ERROR_UNHANDLED_EXCEPTION);
|
2015-12-24 17:32:25 +02:00
|
|
|
use constant ERROR_PROTOCOL_TIMEOUT => ERROR_MINIMUM + 41;
|
|
|
|
push @EXPORT, qw(ERROR_PROTOCOL_TIMEOUT);
|
2016-01-10 06:08:54 +02:00
|
|
|
use constant ERROR_FEATURE_NOT_SUPPORTED => ERROR_MINIMUM + 42;
|
|
|
|
push @EXPORT, qw(ERROR_FEATURE_NOT_SUPPORTED);
|
2015-08-29 20:20:46 +02:00
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
use constant ERROR_INVALID_VALUE => ERROR_MAXIMUM - 1;
|
|
|
|
push @EXPORT, qw(ERROR_INVALID_VALUE);
|
|
|
|
use constant ERROR_UNKNOWN => ERROR_MAXIMUM;
|
2015-08-29 20:20:46 +02:00
|
|
|
push @EXPORT, qw(ERROR_UNKNOWN);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# CONSTRUCTOR
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
my $iCode = shift; # Error code
|
|
|
|
my $strMessage = shift; # ErrorMessage
|
|
|
|
my $strTrace = shift; # Stack trace
|
|
|
|
|
2015-10-08 17:43:56 +02:00
|
|
|
# if ($iCode < ERROR_MINIMUM || $iCode > ERROR_MAXIMUM)
|
|
|
|
# {
|
|
|
|
# $iCode = ERROR_INVALID_VALUE;
|
|
|
|
# }
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Initialize exception
|
|
|
|
$self->{iCode} = $iCode;
|
|
|
|
$self->{strMessage} = $strMessage;
|
|
|
|
$self->{strTrace} = $strTrace;
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# CODE
|
|
|
|
####################################################################################################################################
|
|
|
|
sub code
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{iCode};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# MESSAGE
|
|
|
|
####################################################################################################################################
|
|
|
|
sub message
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{strMessage};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# TRACE
|
|
|
|
####################################################################################################################################
|
|
|
|
sub trace
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{strTrace};
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|