Elasticsearch/Error.pm

filter: Statementstmt 81.2% 65 / 80 Branchbran 71.4% 20 / 28 Conditioncond 46.1% 6 / 13 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 4 totaltotal 70.9% 100 / 141 CC 22 SCAR 20.1
CC
22
Cov
75%
_stack
12.2
stacktrace
12.0
_compare
6.0
CRAP 7.5
« Elasticsearch/Role/CxnPool/Sniff.pm ↑ Summary Elasticsearch/CxnPool/Static.pm »
1 # Licensed to Elasticsearch B.V. under one or more contributor
2 # license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright
4 # ownership. Elasticsearch B.V. licenses this file to you under
5 # the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17  
18 package Search::Elasticsearch::Error;
19 68 $Search::Elasticsearch::Error::VERSION = '8.12';
20 68 our $DEBUG = 0;
21  
22 68 @Search::Elasticsearch::Error::Internal::ISA = __PACKAGE__;
23 68 @Search::Elasticsearch::Error::Param::ISA = __PACKAGE__;
24 68 @Search::Elasticsearch::Error::NoNodes::ISA = __PACKAGE__;
25 68 @Search::Elasticsearch::Error::ProductCheck::ISA = __PACKAGE__;
26 68 @Search::Elasticsearch::Error::Unauthorized::ISA = __PACKAGE__;
27 68 @Search::Elasticsearch::Error::Forbidden::ISA = __PACKAGE__;
28 68 @Search::Elasticsearch::Error::Illegal::ISA = __PACKAGE__;
29 68 @Search::Elasticsearch::Error::Request::ISA = __PACKAGE__;
30 68 @Search::Elasticsearch::Error::Timeout::ISA = __PACKAGE__;
31 68 @Search::Elasticsearch::Error::Cxn::ISA = __PACKAGE__;
32 68 @Search::Elasticsearch::Error::Serializer::ISA = __PACKAGE__;
33  
34 @Search::Elasticsearch::Error::Conflict::ISA
35 68 = ( 'Search::Elasticsearch::Error::Request', __PACKAGE__ );
36  
37 @Search::Elasticsearch::Error::Missing::ISA
38 68 = ( 'Search::Elasticsearch::Error::Request', __PACKAGE__ );
39  
40 @Search::Elasticsearch::Error::RequestTimeout::ISA
41 68 = ( 'Search::Elasticsearch::Error::Request', __PACKAGE__ );
42  
43 @Search::Elasticsearch::Error::ContentLength::ISA
44 68 = ( __PACKAGE__, 'Search::Elasticsearch::Error::Request' );
45  
46 @Search::Elasticsearch::Error::SSL::ISA
47 68 = ( __PACKAGE__, 'Search::Elasticsearch::Error::Cxn' );
48  
49 @Search::Elasticsearch::Error::BadGateway::ISA
50 68 = ( 'Search::Elasticsearch::Error::Cxn', __PACKAGE__ );
51  
52 @Search::Elasticsearch::Error::Unavailable::ISA
53 68 = ( 'Search::Elasticsearch::Error::Cxn', __PACKAGE__ );
54  
55 @Search::Elasticsearch::Error::GatewayTimeout::ISA
56 68 = ( 'Search::Elasticsearch::Error::Cxn', __PACKAGE__ );
57  
58 68 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
59 68 '""' => '_stringify',
60 'cmp' => '_compare',
61 68 );
62  
63 68 ▶use Data::Dumper();
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 #===================================
66 120 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
67 #===================================
68 120 my ( $class, $type, $msg, $vars, $caller ) = @_;
69 120 ▶ return $type if ref $type;
Branch: 1 branch
BranchTrueFalseTotal
if ref $type 27 93 120
70 93 ▶ $caller ||= 0;
Condition100%2/2
$caller ||= 0
l!l
903
MC/DC100%1/1
$caller ||= 0
$caller
Truth table100%2/2
A
A= $caller
Aresult
11
00
71  
72 93 my $error_class = 'Search::Elasticsearch::Error::' . $type;
73 93 ▶ $msg = 'Unknown error' unless defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 0 93 93
74  
75 93 ▶ local $DEBUG = 2 if $type eq 'Internal';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Internal" 0 93 93
76  
77 93 my $stack = $class->_stack;
78  
79 93 my $self = bless {
80 type => $type,
81 text => $msg,
82 vars => $vars,
83 stack => $stack,
84 }, $error_class;
85  
86 93 return $self;
87 }
88  
89 #===================================
90 139 ▶sub is {
Subroutine is: called CC=3 SCAR=11.0
Pod undocumented
91 #===================================
92 139 my $self = shift;
93 139 for (@_) {
94 161 ▶ return 1 if $self->isa("Search::Elasticsearch::Error::$_");
Branch: 1 branch
BranchTrueFalseTotal
if $self->isa("Search::Elasticsearch::Error::$_") 96 65 161
95 }
96 43 return 0;
97 }
98  
99 #===================================
100 129 ▶sub _stringify {
Subroutine _stringify: called CC=4 SCAR=13.9
101 #===================================
102 129 my $self = shift;
103 129 local $Data::Dumper::Terse = 1;
104 129 local $Data::Dumper::Indent = !!$DEBUG;
105  
106 129 ▶ unless ( $self->{msg} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"msg"}) 78 51 129
107 78 my $stack = $self->{stack};
108 78 my $caller = $stack->[0];
109 $self->{msg} = sprintf( "[%s] ** %s, called from sub %s at %s line %d.",
110 78 $self->{type}, $self->{text}, @{$caller}[ 3, 1, 2 ] );
111  
112 78 ▶ if ( $self->{vars} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vars"}) 65 13 78
113 $self->{msg} .= sprintf( " With vars: %s\n",
114 65 Data::Dumper::Dumper $self->{vars} );
115 }
116  
117 78 ▶ if ( @$stack > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack > 1) 0 78 78
118 $self->{msg}
119 0 .= sprintf( "Stacktrace:\n%s\n", $self->stacktrace($stack) );
120 }
121 }
122 129 return $self->{msg};
123  
124 }
125  
126 #===================================
127 0 ▶sub _compare {
Subroutine _compare: not called CC=2 SCAR=17.9
128 #===================================
129 0 my ( $self, $other, $swap ) = @_;
130 0 $self .= '';
131 0 ▶ ( $self, $other ) = ( $other, $self ) if $swap;
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 0 0
132 0 return $self cmp $other;
133 }
134  
135 #===================================
136 93 ▶sub _stack {
Subroutine _stack: called CC=10 SCAR=25.0
137 #===================================
138 93 my $self = shift;
139 93 ▶ my $caller = shift() || 2;
Condition50%1/2
shift() || 2
l!l
093
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
140  
141 93 my @stack;
142 93 ▶ while ( my @caller = caller( ++$caller ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = caller ++$caller) 183 3 186
143 183 ▶ next if $caller[0] eq 'Try::Tiny';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[0] eq "Try::Tiny" 45 138 183
144  
145 138 ▶ if ( $caller[3] =~ /^(.+)::__ANON__\[(.+):(\d+)\]$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($caller[3] =~ /^(.+)::__ANON__\[(.+):(\d+)\]$/) { } 0 138 138
elsif ($caller[1] =~ /^\(eval \d+\)/) { } 0 138 138
146 0 @caller = ( $1, $2, $3, '(ANON)' );
147 }
148 elsif ( $caller[1] =~ /^\(eval \d+\)/ ) {
149 0 $caller[3] = "modified(" . $caller[3] . ")";
150 }
151  
152 next
153 138 ▶ if $caller[0] =~ /^Search::Elasticsearch/
Branch: 1 branch
BranchTrueFalseTotal
if $caller[0] =~ /^Search::Elasticsearch/ and $DEBUG < 2 || $caller[3] eq "Try::Tiny::try" 48 90 138
Condition50%3/6
$caller[0] =~ /^Search::Elasticsearch/ and $DEBUG < 2 || $caller[3] eq "Try::Tiny::try"
!ll&&!rl&&r
90048
$DEBUG < 2 or $caller[3] eq "Try::Tiny::try"
l!l&&r!l&&!r
4800
MC/DC33%1/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 table50%2/4
A and B or C
A= $caller[0] =~ /^Search::Elasticsearch/B= $DEBUG < 2C= $caller[3] eq "Try::Tiny::try"
ABCresult
0XX0
1000
11X1
1011
154 and ( $DEBUG < 2 or $caller[3] eq 'Try::Tiny::try' );
155 90 push @stack, [ @caller[ 0, 1, 2, 3 ] ];
156 90 ▶ last unless $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $DEBUG > 1 90 0 90
157 }
158 93 return \@stack;
159 }
160  
161 #===================================
162 0 ▶sub stacktrace {
Subroutine stacktrace: not called CC=3 SCAR=24.8
Pod undocumented
163 #===================================
164 0 my $self = shift;
165 0 ▶ my $stack = shift || $self->_stack();
Condition0%0/3
shift() || $self->_stack
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->_stack
shift() $self->_stack
Truth table0%0/3
A || B
A= shift()B= $self->_stack
ABresult
1X1
011
000
166  
167 0 my $o = sprintf "%s\n%-4s %-50s %-5s %s\n%s\n",
168 '-' x 80, '#', 'Package', 'Line', 'Sub-routine', '-' x 80;
169  
170 0 my $i = 1;
171 0 for (@$stack) {
172 0 $o .= sprintf "%-4d %-50s %4d %s\n", $i++, @{$_}[ 0, 2, 3 ];
173 }
174  
175 0 return $o .= ( '-' x 80 ) . "\n";
176 }
177  
178 #===================================
179 1 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
180 #===================================
181 1 my $self = shift;
182 1 return $self->_stringify;
183 }
184 68 1;
185  
186 # ABSTRACT: Errors thrown by Search::Elasticsearch
187  
188 __END__
« Elasticsearch/Role/CxnPool/Sniff.pm ↑ Summary Elasticsearch/CxnPool/Static.pm »