Async/Exception.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 75.0% 3 / 4 Conditioncond 77.7% 14 / 18 MC/DCmcdc 55.5% 5 / 9 Subroutinesub 86.6% 13 / 15 Podpod 90.0% 9 / 10 totaltotal 84.0% 74 / 88 CC 11 SCAR 12.9
CC
11
Cov
87%
new
7.1
throw
5.2
stacktrace
2.0
CRAP 3.6
« Async/SelectNormaliser.pm ↑ Summary Async/ResultSet/Pager.pm »
1 package DBIx::Class::Async::Exception;
2  
3 102 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 102 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 102 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 102 our $VERSION = qv('v1.2.0');
8 102 our $AUTHORITY = 'cpan:MANWAR';
9  
10 use overload
11 102 ▶ '""' => \&message,
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 102 fallback => 1;
14  
15 =head1 NAME
16  
17 DBIx::Class::Async::Exception - Base class for DBIx::Class::Async exceptions
18  
19 =head1 VERSION
20  
21 Version v1.2.0
22  
23 =head1 SYNOPSIS
24  
25 # In application code -- catch any async exception
26 use Try::Tiny;
27  
28 try {
29 $rs->async_update_or_create(\%data)->get;
30 } catch {
31 if ( ref $_ && $_->isa('DBIx::Class::Async::Exception::RelationshipAsColumn') ) {
32 warn "Fix your hashref: " . $_->hint;
33 }
34 elsif ( ref $_ && $_->isa('DBIx::Class::Async::Exception') ) {
35 warn "Async DBIC error: " . $_->message;
36 warn "Original: " . $_->original_error if $_->original_error;
37 }
38 else {
39 die $_; # re-throw unknown exceptions
40 }
41 };
42  
43 # Load a specific subclass directly when you need to throw or catch it by name
44 use DBIx::Class::Async::Exception::RelationshipAsColumn;
45  
46 DBIx::Class::Async::Exception::RelationshipAsColumn->throw(
47 message => "Relationship 'Details' passed where a column was expected",
48 relationship => 'Details',
49 source_class => 'My::Schema::Result::Operation',
50 operation => 'update_or_create',
51 hint => "Omit 'Details' from the hashref if you have no related rows.",
52 );
53  
54 =head1 DESCRIPTION
55  
56 Base class for all structured exceptions thrown by L<DBIx::Class::Async>.
57 Consistent with the interface of L<DBIx::Class::Exception>: objects stringify
58 to their message, support boolean overload, and provide C<throw>/C<rethrow>.
59  
60 This module defines only the base class. Each subclass lives in its own file
61 and must be loaded explicitly, or loaded transitively by
62 L<DBIx::Class::Async::Exception::Factory> which loads all subclasses as part
63 of its own initialisation.
64  
65 In normal use you do not need to load this module directly. Loading
66 L<DBIx::Class::Async::Exception::Factory> in C<Async.pm> is sufficient --
67 the Factory loads the base class and all subclasses, and is the sole entry
68 point for translating raw L<DBIx::Class> errors into typed exception objects.
69  
70 =head2 Exception hierarchy
71  
72 DBIx::Class::Async::Exception
73 +-- DBIx::Class::Async::Exception::RelationshipAsColumn
74 +-- DBIx::Class::Async::Exception::NotInStorage
75 +-- DBIx::Class::Async::Exception::MissingColumn
76 +-- DBIx::Class::Async::Exception::NoSuchRelationship
77 +-- DBIx::Class::Async::Exception::AmbiguousColumn
78  
79 =cut
80  
81 23 ▶sub new {
Subroutine new: called CC=7 SCAR=19.7
Pod undocumented
82 23 my ($class, %args) = @_;
83 return bless {
84 message => $args{message} // '(no message)',
85 hint => $args{hint} // undef,
86 original_error => $args{original_error} // undef,
87 operation => $args{operation} // undef,
88 source_class => $args{source_class} // undef,
89 stacktrace => $args{stacktrace} // undef,
90 23 ▶ }, $class;
Condition83%10/12
$args{"message"} // "(no message)"
l!l
230
$args{"hint"} // undef
l!l
1112
$args{"original_error"} // undef
l!l
149
$args{"operation"} // undef
l!l
1112
$args{"source_class"} // undef
l!l
1013
$args{"stacktrace"} // undef
l!l
023
MC/DC0%0/1
$args{"message"} // "(no message)"
$args{"message"}
MC/DC100%1/1
$args{"hint"} // undef
$args{"hint"}
MC/DC100%1/1
$args{"original_error"} // undef
$args{"original_error"}
MC/DC100%1/1
$args{"operation"} // undef
$args{"operation"}
MC/DC100%1/1
$args{"source_class"} // undef
$args{"source_class"}
MC/DC0%0/1
$args{"stacktrace"} // undef
$args{"stacktrace"}
Truth table50%1/2
A
A= $args{"message"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"hint"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"original_error"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"operation"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"source_class"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"stacktrace"}
Aresult
11
00
91 }
92  
93 =head1 METHODS
94  
95 =head2 throw
96  
97 DBIx::Class::Async::Exception->throw(%args);
98 DBIx::Class::Async::Exception->throw($exception_object);
99  
100 Constructs and throws an exception. C<%args> are passed to C<new()>. If a
101 single argument is passed and is already an instance of this class or a
102 subclass, it is re-thrown as-is -- consistent with L<DBIx::Class::Exception/throw>.
103  
104 =cut
105  
106 20 ▶sub throw {
Subroutine throw: called CC=5 SCAR=16.5
Pod documented
107 20 my ($class, @args) = @_;
108  
109 20 ▶ if ( @args == 1 && ref $args[0] && $args[0]->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and ref $args[0] and $args[0]->isa(__PACKAGE__)) 1 19 20
Condition66%4/6
@args == 1 and ref $args[0] and $args[0]->isa(__PACKAGE__)
!ll&&!rl&&r
1901
@args == 1 and ref $args[0]
!ll&&!rl&&r
1901
MC/DC33%1/3
@args == 1 and ref $args[0] and $args[0]->isa(__PACKAGE__)
@args == 1 ref $args[0] $args[0]->isa(__PACKAGE__)
Truth table50%2/4
A and B and C
A= @args == 1B= ref $args[0]C= $args[0]->isa(__PACKAGE__)
ABCresult
0XX0
10X0
1100
1111
110 1 $args[0]->rethrow;
111 }
112  
113 19 ▶ my %args = @args == 1 ? (message => $args[0]) : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 0 19 19
114 19 die $class->new(%args);
115 }
116  
117 =head2 rethrow
118  
119 $exception->rethrow;
120  
121 Re-throws the exception object without modifying it.
122  
123 =cut
124  
125 3 ▶sub rethrow {
Subroutine rethrow: called CC=1 SCAR=0.0
Pod documented
126 3 my ($self) = @_;
127 3 die $self;
128 }
129  
130 =head2 message
131  
132 The human-readable error message. Also what the object stringifies to.
133  
134 =cut
135  
136 14 ▶sub message { $_[0]->{message} }
Subroutine message: called CC=1 SCAR=0.0
Pod documented
137  
138 =head2 hint
139  
140 An optional actionable suggestion for how to fix the problem.
141  
142 =cut
143  
144 6 ▶sub hint { $_[0]->{hint} }
Subroutine hint: called CC=1 SCAR=0.0
Pod documented
145  
146 =head2 original_error
147  
148 The raw exception string from L<DBIx::Class>, preserved for debugging or logging.
149  
150 =cut
151  
152 3 ▶sub original_error { $_[0]->{original_error} }
Subroutine original_error: called CC=1 SCAR=0.0
Pod documented
153  
154 =head2 operation
155  
156 The DBIC operation being performed when the error occurred,
157 e.g. C<'update_or_create'>, C<'create'>, C<'find'>. May be undef.
158  
159 =cut
160  
161 4 ▶sub operation { $_[0]->{operation} }
Subroutine operation: called CC=1 SCAR=0.0
Pod documented
162  
163 =head2 source_class
164  
165 The fully-qualified result class associated with the error,
166 e.g. C<'My::Schema::Result::Operation'>. May be undef.
167  
168 =cut
169  
170 1 ▶sub source_class { $_[0]->{source_class} }
Subroutine source_class: called CC=1 SCAR=0.0
Pod documented
171  
172 =head2 stacktrace
173  
174 Optional stack trace string, populated when C<< stacktrace => 1 >> is passed
175 to C<throw> or C<new>, mirroring L<DBIx::Class::Exception> behaviour.
176  
177 =cut
178  
179 0 ▶sub stacktrace { $_[0]->{stacktrace} }
Subroutine stacktrace: not called CC=1 SCAR=6.9
Pod documented
180  
181 =head2 stringify
182  
183 Alias for C<message>. Called automatically by the C<""> overload.
184  
185 =cut
186  
187 0 ▶sub stringify { $_[0]->message }
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
188  
189 =head1 SUBCLASSES
190  
191 Each subclass lives in its own file. Load a subclass directly when you need
192 to reference it by name, or use L<DBIx::Class::Async::Exception::Factory>
193 which loads all subclasses as part of its own initialisation.
194  
195 =over 4
196  
197 =item L<DBIx::Class::Async::Exception::RelationshipAsColumn>
198  
199 Thrown when a relationship name is passed as a hashref key with an C<undef>
200 value (RT#127065). Adds: C<relationship>, C<relationship_type>.
201  
202 =item L<DBIx::Class::Async::Exception::NotInStorage>
203  
204 Thrown when C<update()> or C<delete()> is called on an un-inserted row.
205 Adds: C<row_class>.
206  
207 =item L<DBIx::Class::Async::Exception::MissingColumn>
208  
209 Thrown when a required column is absent from a create/insert hashref.
210 Adds: C<column>.
211  
212 =item L<DBIx::Class::Async::Exception::NoSuchRelationship>
213  
214 Thrown when a relationship name used in C<join>/C<prefetch> is not declared.
215 Adds: C<relationship>.
216  
217 =item L<DBIx::Class::Async::Exception::AmbiguousColumn>
218  
219 Thrown when a column name is ambiguous across joined tables.
220 Adds: C<column>.
221  
222 =back
223  
224 =head1 SEE ALSO
225  
226 L<DBIx::Class::Async::Exception::Factory>
227  
228 =head1 AUTHOR
229  
230 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
231  
232 =head1 REPOSITORY
233  
234 L<https://github.com/manwar/DBIx-Class-Async>
235  
236 =head1 BUGS
237  
238 Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/DBIx-Class-Async/issues>.
239 I will be notified and then you'll automatically be notified of progress on your
240 bug as I make changes.
241  
242 =head1 SUPPORT
243  
244 You can find documentation for this module with the perldoc command.
245  
246 perldoc DBIx::Class::Async::Exception
247  
248 You can also look for information at:
249  
250 =over 4
251  
252 =item * BUG Report
253  
254 L<https://github.com/manwar/DBIx-Class-Async/issues>
255  
256 =item * CPAN Ratings
257  
258 L<http://cpanratings.perl.org/d/DBIx-Class-Async>
259  
260 =item * Search MetaCPAN
261  
262 L<https://metacpan.org/dist/DBIx-Class-Async/>
263  
264 =back
265  
266 =head1 LICENSE AND COPYRIGHT
267  
268 Copyright (C) 2026 Mohammad Sajid Anwar.
269  
270 This program is free software; you can redistribute it and / or modify it under
271 the terms of the the Artistic License (2.0). You may obtain a copy of the full
272 license at:
273 L<http://www.perlfoundation.org/artistic_license_2_0>
274 Any use, modification, and distribution of the Standard or Modified Versions is
275 governed by this Artistic License.By using, modifying or distributing the Package,
276 you accept this license. Do not use, modify, or distribute the Package, if you do
277 not accept this license.
278 If your Modified Version has been derived from a Modified Version made by someone
279 other than you,you are nevertheless required to ensure that your Modified Version
280 complies with the requirements of this license.
281 This license does not grant you the right to use any trademark, service mark,
282 tradename, or logo of the Copyright Holder.
283 This license includes the non-exclusive, worldwide, free-of-charge patent license
284 to make, have made, use, offer to sell, sell, import and otherwise transfer the
285 Package with respect to any patent claims licensable by the Copyright Holder that
286 are necessarily infringed by the Package. If you institute patent litigation
287 (including a cross-claim or counterclaim) against any party alleging that the
288 Package constitutes direct or contributory patent infringement,then this Artistic
289 License to you shall terminate on the date that such litigation is filed.
290 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
291 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
292 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
293 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
294 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
295 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
296 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
297  
298 =cut
299  
300 102 1; # End of DBIx::Class::Async::Exception
« Async/SelectNormaliser.pm ↑ Summary Async/ResultSet/Pager.pm »