2015-08-29 20:20:46 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# COMMON EXCEPTION MODULE
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
package pgBackRest::Common::Exception;
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess longmess);
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
use Scalar::Util qw(blessed);
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Exception codes
|
|
|
|
####################################################################################################################################
|
2017-04-12 18:41:34 +02:00
|
|
|
use constant ERROR_MINIMUM => 25;
|
2015-10-08 17:43:56 +02:00
|
|
|
push @EXPORT, qw(ERROR_MINIMUM);
|
2017-04-12 18:41:34 +02:00
|
|
|
use constant ERROR_MAXIMUM => 125;
|
2015-10-08 17:43:56 +02:00
|
|
|
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);
|
2016-12-20 23:52:20 +02:00
|
|
|
use constant ERROR_PATH_NOT_EMPTY => ERROR_MINIMUM + 15;
|
|
|
|
push @EXPORT, qw(ERROR_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);
|
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);
|
2016-01-11 16:50:45 +02:00
|
|
|
use constant ERROR_ARCHIVE_COMMAND_INVALID => ERROR_MINIMUM + 43;
|
|
|
|
push @EXPORT, qw(ERROR_ARCHIVE_COMMAND_INVALID);
|
2016-01-15 14:07:00 +02:00
|
|
|
use constant ERROR_LINK_EXPECTED => ERROR_MINIMUM + 44;
|
|
|
|
push @EXPORT, qw(ERROR_LINK_EXPECTED);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant ERROR_LINK_DESTINATION => ERROR_MINIMUM + 45;
|
|
|
|
push @EXPORT, qw(ERROR_LINK_DESTINATION);
|
2016-01-15 14:07:00 +02:00
|
|
|
use constant ERROR_TABLESPACE_IN_PGDATA => ERROR_MINIMUM + 46;
|
|
|
|
push @EXPORT, qw(ERROR_TABLESPACE_IN_PGDATA);
|
2016-01-16 06:37:17 +02:00
|
|
|
use constant ERROR_HOST_INVALID => ERROR_MINIMUM + 47;
|
|
|
|
push @EXPORT, qw(ERROR_HOST_INVALID);
|
2016-02-06 23:49:12 +02:00
|
|
|
use constant ERROR_PATH_MISSING => ERROR_MINIMUM + 48;
|
|
|
|
push @EXPORT, qw(ERROR_PATH_MISSING);
|
2016-02-12 04:42:27 +02:00
|
|
|
use constant ERROR_FILE_MOVE => ERROR_MINIMUM + 49;
|
|
|
|
push @EXPORT, qw(ERROR_FILE_MOVE);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant ERROR_BACKUP_SET_INVALID => ERROR_MINIMUM + 50;
|
|
|
|
push @EXPORT, qw(ERROR_BACKUP_SET_INVALID);
|
|
|
|
use constant ERROR_TABLESPACE_MAP => ERROR_MINIMUM + 51;
|
|
|
|
push @EXPORT, qw(ERROR_TABLESPACE_MAP);
|
|
|
|
use constant ERROR_PATH_TYPE => ERROR_MINIMUM + 52;
|
|
|
|
push @EXPORT, qw(ERROR_PATH_TYPE);
|
|
|
|
use constant ERROR_LINK_MAP => ERROR_MINIMUM + 53;
|
|
|
|
push @EXPORT, qw(ERROR_LINK_MAP);
|
2016-05-11 15:21:39 +02:00
|
|
|
use constant ERROR_FILE_CLOSE => ERROR_MINIMUM + 54;
|
|
|
|
push @EXPORT, qw(ERROR_FILE_CLOSE);
|
|
|
|
use constant ERROR_DB_MISSING => ERROR_MINIMUM + 55;
|
|
|
|
push @EXPORT, qw(ERROR_DB_MISSING);
|
|
|
|
use constant ERROR_DB_INVALID => ERROR_MINIMUM + 56;
|
|
|
|
push @EXPORT, qw(ERROR_DB_INVALID);
|
2016-06-12 15:13:46 +02:00
|
|
|
use constant ERROR_ARCHIVE_TIMEOUT => ERROR_MINIMUM + 57;
|
|
|
|
push @EXPORT, qw(ERROR_ARCHIVE_TIMEOUT);
|
2016-06-24 14:12:58 +02:00
|
|
|
use constant ERROR_FILE_MODE => ERROR_MINIMUM + 58;
|
|
|
|
push @EXPORT, qw(ERROR_FILE_MODE);
|
2016-08-16 02:15:17 +02:00
|
|
|
use constant ERROR_OPTION_MULTIPLE_VALUE => ERROR_MINIMUM + 59;
|
|
|
|
push @EXPORT, qw(ERROR_OPTION_MULTIPLE_VALUE);
|
2016-08-24 18:39:27 +02:00
|
|
|
use constant ERROR_PROTOCOL_OUTPUT_REQUIRED => ERROR_MINIMUM + 60;
|
|
|
|
push @EXPORT, qw(ERROR_PROTOCOL_OUTPUT_REQUIRED);
|
2016-09-06 15:15:22 +02:00
|
|
|
use constant ERROR_LINK_OPEN => ERROR_MINIMUM + 61;
|
|
|
|
push @EXPORT, qw(ERROR_LINK_OPEN);
|
2016-09-29 01:45:33 +02:00
|
|
|
use constant ERROR_ARCHIVE_DISABLED => ERROR_MINIMUM + 62;
|
|
|
|
push @EXPORT, qw(ERROR_ARCHIVE_DISABLED);
|
2017-01-05 22:19:56 +02:00
|
|
|
use constant ERROR_FILE_OWNER => ERROR_MINIMUM + 63;
|
|
|
|
push @EXPORT, qw(ERROR_FILE_OWNER);
|
|
|
|
use constant ERROR_USER_MISSING => ERROR_MINIMUM + 64;
|
|
|
|
push @EXPORT, qw(ERROR_USER_MISSING);
|
2016-12-04 16:25:40 +02:00
|
|
|
use constant ERROR_OPTION_COMMAND => ERROR_MINIMUM + 65;
|
|
|
|
push @EXPORT, qw(ERROR_OPTION_COMMAND);
|
2017-01-05 22:19:56 +02:00
|
|
|
use constant ERROR_GROUP_MISSING => ERROR_MINIMUM + 66;
|
|
|
|
push @EXPORT, qw(ERROR_GROUP_MISSING);
|
2015-08-29 20:20:46 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
use constant ERROR_INVALID_VALUE => ERROR_MAXIMUM - 2;
|
2015-10-08 17:43:56 +02:00
|
|
|
push @EXPORT, qw(ERROR_INVALID_VALUE);
|
2016-09-06 15:44:50 +02:00
|
|
|
use constant ERROR_UNHANDLED => ERROR_MAXIMUM - 1;
|
|
|
|
push @EXPORT, qw(ERROR_UNHANDLED);
|
2015-10-08 17:43:56 +02:00
|
|
|
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
|
2016-10-05 15:09:30 +02:00
|
|
|
my $strLevel = shift; # Log level
|
2015-08-29 20:20:46 +02:00
|
|
|
my $iCode = shift; # Error code
|
|
|
|
my $strMessage = shift; # ErrorMessage
|
|
|
|
my $strTrace = shift; # Stack trace
|
2016-12-04 01:01:17 +02:00
|
|
|
my $rExtra = shift; # Extra info used exclusively by the logging system
|
2015-08-29 20:20:46 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
if ($iCode < ERROR_MINIMUM || $iCode > ERROR_MAXIMUM)
|
|
|
|
{
|
|
|
|
$iCode = ERROR_INVALID_VALUE;
|
|
|
|
}
|
2015-10-08 17:43:56 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Initialize exception
|
2016-10-05 15:09:30 +02:00
|
|
|
$self->{strLevel} = $strLevel;
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->{iCode} = $iCode;
|
|
|
|
$self->{strMessage} = $strMessage;
|
|
|
|
$self->{strTrace} = $strTrace;
|
2016-12-04 01:01:17 +02:00
|
|
|
$self->{rExtra} = $rExtra;
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2016-10-05 15:09:30 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# level
|
|
|
|
####################################################################################################################################
|
|
|
|
sub level
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{strLevel};
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# CODE
|
|
|
|
####################################################################################################################################
|
|
|
|
sub code
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{iCode};
|
|
|
|
}
|
|
|
|
|
2016-12-04 01:01:17 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# extra
|
|
|
|
####################################################################################################################################
|
|
|
|
sub extra
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{rExtra};
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# MESSAGE
|
|
|
|
####################################################################################################################################
|
|
|
|
sub message
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{strMessage};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# TRACE
|
|
|
|
####################################################################################################################################
|
|
|
|
sub trace
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return $self->{strTrace};
|
|
|
|
}
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# isException
|
|
|
|
#
|
|
|
|
# Is this a structured exception?
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isException
|
|
|
|
{
|
|
|
|
my $oException = shift;
|
|
|
|
|
|
|
|
return defined($oException) && blessed($oException) && $oException->isa('pgBackRest::Common::Exception') ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(isException);
|
|
|
|
|
2017-01-27 16:56:26 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# exceptionCode
|
|
|
|
#
|
|
|
|
# Extract the error code from an exception - if a Perl exception return ERROR_UNKNOWN.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub exceptionCode
|
|
|
|
{
|
|
|
|
my $oException = shift;
|
|
|
|
|
|
|
|
return isException($oException) ? $oException->code() : ERROR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(exceptionCode);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# exceptionMessage
|
|
|
|
#
|
|
|
|
# Extract the error message from an exception - if a Perl exception return bare exception.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub exceptionMessage
|
|
|
|
{
|
|
|
|
my $oException = shift;
|
|
|
|
|
|
|
|
return isException($oException) ? $oException->message() : $oException;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(exceptionMessage);
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
1;
|