Elasticsearch/Error.pm

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