| 1 | package Search::Elasticsearch::Error; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 70 | $Search::Elasticsearch::Error::VERSION = '6.80'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 70 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 70 | @Search::Elasticsearch::Error::Internal::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 70 | @Search::Elasticsearch::Error::Param::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 7 | 70 | @Search::Elasticsearch::Error::NoNodes::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 70 | @Search::Elasticsearch::Error::Unauthorized::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 70 | @Search::Elasticsearch::Error::Forbidden::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 70 | @Search::Elasticsearch::Error::Illegal::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 70 | @Search::Elasticsearch::Error::Request::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 70 | @Search::Elasticsearch::Error::Timeout::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 70 | @Search::Elasticsearch::Error::Cxn::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 70 | @Search::Elasticsearch::Error::Serializer::ISA = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | @Search::Elasticsearch::Error::Conflict::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 70 | = ( 'Search::Elasticsearch::Error::Request', __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | @Search::Elasticsearch::Error::Missing::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 70 | = ( 'Search::Elasticsearch::Error::Request', __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | @Search::Elasticsearch::Error::RequestTimeout::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 70 | = ( 'Search::Elasticsearch::Error::Request', __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | @Search::Elasticsearch::Error::ContentLength::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 70 | = ( __PACKAGE__, 'Search::Elasticsearch::Error::Request' ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | @Search::Elasticsearch::Error::SSL::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 70 | = ( __PACKAGE__, 'Search::Elasticsearch::Error::Cxn' ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | @Search::Elasticsearch::Error::BadGateway::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 70 | = ( 'Search::Elasticsearch::Error::Cxn', __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | @Search::Elasticsearch::Error::Unavailable::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 70 | = ( 'Search::Elasticsearch::Error::Cxn', __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | @Search::Elasticsearch::Error::GatewayTimeout::ISA | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 70 | = ( 'Search::Elasticsearch::Error::Cxn', __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | use overload ( | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 70 | '""' => '_stringify', | |||||||||||||||||||||||||||||||||||||||||
| 42 | 'cmp' => '_compare', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 70 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 70 | ▶ | use Data::Dumper(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 48 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 119 | ▶ | my ( $class, $type, $msg, $vars, $caller ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 119 | ▶ | return $type if ref $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 92 | ▶ | $caller ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$caller ||= 0
MC/DC100%1/1
$caller ||= 0
$caller
Truth table100%2/2
A
A= $caller
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 92 | my $error_class = 'Search::Elasticsearch::Error::' . $type; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 92 | ▶ | $msg = 'Unknown error' unless defined $msg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 92 | ▶ | local $DEBUG = 2 if $type eq 'Internal'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 92 | my $stack = $class->_stack; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 92 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 62 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | text => $msg, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | vars => $vars, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | stack => $stack, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | }, $error_class; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 92 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 72 | sub is { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 139 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 139 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 76 | 161 | ▶ | return 1 if $self->isa("Search::Elasticsearch::Error::$_"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 43 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 82 | sub _stringify { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 174 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stringify: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 174 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 174 | local $Data::Dumper::Indent = !!$DEBUG; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 174 | ▶ | unless ( $self->{msg} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 77 | my $stack = $self->{stack}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 77 | my $caller = $stack->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 91 | $self->{msg} = sprintf( "[%s] ** %s, called from sub %s at %s line %d.", | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 77 | $self->{type}, $self->{text}, @{$caller}[ 3, 1, 2 ] ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 77 | ▶ | if ( $self->{vars} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | $self->{msg} .= sprintf( " With vars: %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 65 | Data::Dumper::Dumper $self->{vars} ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 77 | ▶ | if ( @$stack > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | $self->{msg} | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | .= sprintf( "Stacktrace:\n%s\n", $self->stacktrace($stack) ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 174 | return $self->{msg}; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 109 | sub _compare { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my ( $self, $other, $swap ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compare: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self .= ''; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | ( $self, $other ) = ( $other, $self ) if $swap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return $self cmp $other; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 118 | sub _stack { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 92 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stack: called CC=10 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 92 | ▶ | my $caller = shift() || 2; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 2
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 92 | my @stack; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 92 | ▶ | while ( my @caller = caller( ++$caller ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 182 | ▶ | next if $caller[0] eq 'Try::Tiny'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 137 | ▶ | if ( $caller[3] =~ /^(.+)::__ANON__\[(.+):(\d+)\]$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | @caller = ( $1, $2, $3, '(ANON)' ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | elsif ( $caller[1] =~ /^\(eval \d+\)/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $caller[3] = "modified(" . $caller[3] . ")"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | next | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 137 | ▶ | if $caller[0] =~ /^Search::Elasticsearch/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$caller[0] =~ /^Search::Elasticsearch/ and $DEBUG < 2 || $caller[3] eq "Try::Tiny::try"
$DEBUG < 2 or $caller[3] eq "Try::Tiny::try"
MC/DC0%0/3
$caller[0] =~ /^Search::Elasticsearch/ and $DEBUG < 2 || $caller[3] eq "Try::Tiny::try"
$caller[0] =~ /^Search::Elasticsearch/
$DEBUG < 2
$caller[3] eq "Try::Tiny::try"
Truth table25%1/4
A and B or C
A= $caller[0] =~ /^Search::Elasticsearch/B= $DEBUG < 2C= $caller[3] eq "Try::Tiny::try"
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | and ( $DEBUG < 2 or $caller[3] eq 'Try::Tiny::try' ); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 89 | push @stack, [ @caller[ 0, 1, 2, 3 ] ]; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 89 | ▶ | last unless $DEBUG > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 92 | return \@stack; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 144 | sub stacktrace { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stacktrace: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my $stack = shift || $self->_stack(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $self->_stack
MC/DC0%0/2
shift() || $self->_stack
shift()
$self->_stack
Truth table0%0/3
A || B
A= shift()B= $self->_stack
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $o = sprintf "%s\n%-4s %-50s %-5s %s\n%s\n", | |||||||||||||||||||||||||||||||||||||||||
| 150 | '-' x 80, '#', 'Package', 'Line', 'Sub-routine', '-' x 80; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | for (@$stack) { | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $o .= sprintf "%-4d %-50s %4d %s\n", $i++, @{$_}[ 0, 2, 3 ]; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return $o .= ( '-' x 80 ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 161 | sub TO_JSON { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | return $self->_stringify; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 70 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | # ABSTRACT: Errors thrown by Search::Elasticsearch | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | __END__ | ||||||||||||||||||||||||||||||||||||||||||