Elasticsearch/Error.pm

filter: Statementstmt 81.0% 64 / 79 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.0% 98 / 140 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/Client/6_0/Role/Scroll.pm »
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
BranchTrueFalseTotal
if ref $type 27 92 119
52 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
53  
54 92 my $error_class = 'Search::Elasticsearch::Error::' . $type;
55 92 ▶ $msg = 'Unknown error' unless defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 0 92 92
56  
57 92 ▶ local $DEBUG = 2 if $type eq 'Internal';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Internal" 0 92 92
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
BranchTrueFalseTotal
if $self->isa("Search::Elasticsearch::Error::$_") 96 65 161
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
BranchTrueFalseTotal
unless ($self->{"msg"}) 77 97 174
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
BranchTrueFalseTotal
if ($self->{"vars"}) 65 12 77
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
BranchTrueFalseTotal
if (@$stack > 1) 0 77 77
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
BranchTrueFalseTotal
if $swap 0 0 0
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
l!l
092
MC/DC0%0/1
shift() || 2
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
122  
123 92 my @stack;
124 92 ▶ while ( my @caller = caller( ++$caller ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = caller ++$caller) 182 3 185
125 182 ▶ next if $caller[0] eq 'Try::Tiny';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[0] eq "Try::Tiny" 45 137 182
126  
127 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
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
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
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
BranchTrueFalseTotal
unless $DEBUG > 1 89 0 89
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
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
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__
« Elasticsearch/Role/CxnPool/Sniff.pm ↑ Summary Elasticsearch/Client/6_0/Role/Scroll.pm »