Client/Error.pm

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