Catmandu/Error.pm

filter: Statementstmt 100% 236 / 236 Branchbran 81.8% 18 / 22 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 49 / 49 Podpod 0.0% 0 / 7 totaltotal 95.9% 304 / 317 CC 14 SCAR 4.8
CC
14
Cov
98%
log_message
4.0
log_message
3.0
_source_log_message
3.0
CRAP 1.6
« Catmandu/Hits.pm ↑ Summary Catmandu/Exporter/Multi.pm »
1 package Catmandu::Error;
2  
3 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 177 our $VERSION = '1.2025';
6  
7 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 177 extends 'Throwable::Error';
11  
12 177 with 'Catmandu::Logger';
13  
14 has message => (
15 is => 'lazy',
16 64 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
17 64 ▶ my $msg = $_[0] // "";
Condition50%1/2
$_[0] // ""
l!l
640
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
18 64 $msg =~ s/\s+$//;
19 64 $msg;
20 }
21 177 );
22  
23 64 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
24 64 my ($self) = @_;
25 64 my $msg = $self->log_message;
26 64 ▶ if ($self->log->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log->is_debug) 8 56 64
27 8 $msg .= "\n\n" . $self->stack_trace->as_string;
28 }
29 64 $self->log->error($msg);
30 }
31  
32 30 ▶sub log_message {
Subroutine log_message: called CC=1 SCAR=0.0
Pod undocumented
33 30 $_[0]->message;
34 }
35  
36 2 ▶sub _build_message {
Subroutine _build_message: called CC=1 SCAR=0.0
37 2 "";
38 }
39  
40 package Catmandu::Error::Source;
41  
42 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 177 our $VERSION = '1.2025';
45  
46 177 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 177 ▶use Catmandu::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 177 has source => (is => 'rw', writer => 'set_source');
51  
52 24 ▶sub _source_log_message {
Subroutine _source_log_message: called CC=3 SCAR=11.0
53 24 my $msg = "";
54 24 ▶ if (Catmandu::Util::is_string(my $source = $_[0]->source)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Catmandu::Util::is_string(my $source = $_[0]->source)) 17 7 24
55 17 $msg .= "\nSource:";
56 17 for (split(/\n/, $source)) {
57 17 $msg .= "\n\t$_";
58 }
59 }
60 24 $msg;
61 }
62  
63 package Catmandu::BadVal;
64  
65 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 177 our $VERSION = '1.2025';
68  
69 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 177 extends 'Catmandu::Error';
73  
74 package Catmandu::BadArg;
75  
76 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 177 our $VERSION = '1.2025';
79  
80 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 177 extends 'Catmandu::BadVal';
84  
85 package Catmandu::NotImplemented;
86  
87 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 177 our $VERSION = '1.2025';
90  
91 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 177 extends 'Catmandu::Error';
95  
96 package Catmandu::NoSuchPackage;
97  
98 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 177 our $VERSION = '1.2025';
101  
102 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 177 extends 'Catmandu::Error';
106  
107 177 has package_name => (is => 'ro');
108  
109 12 ▶sub log_message {
Subroutine log_message: called CC=4 SCAR=13.9
Pod undocumented
110 12 my ($self) = @_;
111 12 my $err = $self->message;
112 12 my $pkg_name = $self->package_name;
113 12 my $msg = "Failed to load $pkg_name";
114 12 ▶ if (my ($type, $name)
Branch: 2 branches
BranchTrueFalseTotal
if (() = $pkg_name =~ /^Catmandu::(Importer|Exporter|Store)::(\S+)/) { } 5 7 12
elsif ($pkg_name =~ /^Catmandu::Fix::\S+/) { } 7 0 7
115 = $pkg_name =~ /^Catmandu::(Importer|Exporter|Store)::(\S+)/)
116 {
117 5 $msg
118 = "Can't find the "
119 . lc($type)
120 . " '$name' in your configuration file or $pkg_name is not installed.";
121 }
122 elsif ($pkg_name =~ /^Catmandu::Fix::\S+/) {
123 7 my ($fix_name) = $pkg_name =~ /([^:]+)$/;
124 7 ▶ if ($fix_name =~ /^[a-z]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fix_name =~ /^[a-z]/) 7 0 7
125 7 $msg
126 = "Tried to execute the fix '$fix_name' but can't find $pkg_name on your system.";
127 }
128 }
129 12 $msg .= "\nError: $err";
130 12 $msg .= "\nPackage name: $pkg_name";
131 12 $msg;
132 }
133  
134 package Catmandu::FixParseError;
135  
136 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 177 our $VERSION = '1.2025';
139  
140 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
141 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 177 extends 'Catmandu::Error';
144  
145 177 with 'Catmandu::Error::Source';
146  
147 17 ▶sub log_message {
Subroutine log_message: called CC=1 SCAR=0.0
Pod undocumented
148 17 my ($self) = @_;
149 17 my $err = $self->message;
150 17 my $msg = "Syntax error in your fixes...";
151 17 $msg .= "\nError: $err";
152 17 $msg .= $self->_source_log_message;
153 17 $msg;
154 }
155  
156 package Catmandu::NoSuchFixPackage;
157  
158 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 177 our $VERSION = '1.2025';
161  
162 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
163 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
164  
165 177 extends 'Catmandu::NoSuchPackage';
166  
167 177 with 'Catmandu::Error::Source';
168  
169 177 has fix_name => (is => 'ro');
170  
171 4 ▶around log_message => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
172 4 my ($orig, $self) = @_;
173 4 my $fix_name = $self->fix_name;
174 4 my $msg = $orig->($self);
175 4 ▶ $msg .= "\nFix name: $fix_name" if $fix_name;
Branch: 1 branch
BranchTrueFalseTotal
if $fix_name 4 0 4
176 4 $msg .= $self->_source_log_message;
177 4 $msg;
178 177 };
179  
180 package Catmandu::BadFixArg;
181  
182 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 177 our $VERSION = '1.2025';
185  
186 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
187 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
188  
189 177 extends 'Catmandu::BadArg';
190  
191 177 with 'Catmandu::Error::Source';
192  
193 177 has package_name => (is => 'ro');
194 177 has fix_name => (is => 'ro');
195  
196 3 ▶sub log_message {
Subroutine log_message: called CC=1 SCAR=0.0
Pod undocumented
197 3 my ($self) = @_;
198 3 my $err = $self->message;
199 3 my $fix_name = $self->fix_name;
200 3 my $msg
201 = "The fix '$fix_name' was called with missing or wrong arguments.";
202 3 $msg .= "\nError: $err";
203 3 $msg .= $self->_source_log_message;
204 3 $msg;
205 }
206  
207 package Catmandu::FixError;
208  
209 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
210  
211 177 our $VERSION = '1.2025';
212  
213 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
214 177 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
215 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
216  
217 177 extends 'Catmandu::Error';
218  
219 177 has data => (is => 'ro');
220 177 has fix => (is => 'ro');
221  
222 3 ▶sub log_message {
Subroutine log_message: called CC=3 SCAR=11.0
Pod undocumented
223 3 my ($self) = @_;
224 3 my $err = $self->message;
225 3 my $fix = $self->fix;
226 3 my $data = $self->data;
227 3 my $msg = "One of your fixes threw an error...";
228 3 $msg .= "\nError: $err";
229 3 ▶ $msg .= "\nSource: $fix" if $fix;
Branch: 1 branch
BranchTrueFalseTotal
if $fix 0 3 3
230 3 ▶ $msg .= "\nInput:\n" . Dumper($data) if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 1 2 3
231 3 $msg;
232 }
233  
234 package Catmandu::HTTPError;
235  
236 177 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
237  
238 177 our $VERSION = '1.2025';
239  
240 177 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
241 177 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
242 177 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
243  
244 # avoid circular dependencies
245 177 require Catmandu::Util;
246  
247 177 extends 'Catmandu::Error';
248  
249 177 has code => (is => 'ro');
250 177 has url => (is => 'ro');
251 177 has method => (is => 'ro');
252 177 has request_headers => (is => 'ro');
253 177 has request_body => (is => 'ro');
254 177 has response_headers => (is => 'ro');
255 177 has response_body => (is => 'ro');
256  
257 6 ▶sub log_message {
Subroutine log_message: called CC=3 SCAR=11.0
Pod undocumented
258 6 my ($self) = @_;
259 6 my $err = $self->message;
260 6 my $code = $self->code;
261 6 my $url = $self->url;
262 6 my $method = $self->method;
263 6 my $request_body = $self->request_body;
264 6 my $response_body = $self->response_body;
265 6 my $request_headers = $self->request_headers;
266 6 my $response_headers = $self->response_headers;
267 6 my $msg = "Got a HTTP error...";
268 6 $msg .= "\nError: $err";
269 6 $msg .= "\nCode: $code";
270 6 $msg .= "\nURL: $url";
271 6 $msg .= "\nMethod: $method";
272 6 $msg .= "\nRequest headers: "
273 . $self->_headers_to_string($request_headers);
274  
275 6 ▶ if (Catmandu::Util::is_string($request_body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Catmandu::Util::is_string($request_body)) 1 5 6
276 1 $msg .= "\nRequest body: \n" . $self->_indent($request_body);
277 }
278 6 $msg .= "\nResponse headers: "
279 . $self->_headers_to_string($response_headers);
280 6 ▶ if (Catmandu::Util::is_string($response_body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Catmandu::Util::is_string($response_body)) 5 1 6
281 5 $msg .= "\nResponse body: \n" . $self->_indent($response_body);
282 }
283 6 $msg;
284 }
285  
286 12 ▶sub _headers_to_string {
Subroutine _headers_to_string: called CC=2 SCAR=6.9
287 12 my ($self, $headers) = @_;
288 12 my $str = "";
289 12 ▶ for (my $i = 0; $i < @$headers; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$headers) 29 12 41
290 29 $str .= "\n\t" . $headers->[$i++] . ": " . $headers->[$i];
291 }
292 12 $str;
293 }
294  
295 6 ▶sub _indent {
Subroutine _indent: called CC=1 SCAR=0.0
296 6 my ($self, $str) = @_;
297 6 $str =~ s/([^\r\n]+)/\t$1/g;
298 6 $str;
299 }
300  
301 177 1;
302  
303 __END__
« Catmandu/Hits.pm ↑ Summary Catmandu/Exporter/Multi.pm »