| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::FreeIPA::Error; |
|
2
|
|
|
|
|
|
|
$Net::FreeIPA::Error::VERSION = '3.0.2'; |
|
3
|
9
|
|
|
9
|
|
481
|
use strict; |
|
|
9
|
|
|
|
|
24
|
|
|
|
9
|
|
|
|
|
238
|
|
|
4
|
9
|
|
|
9
|
|
36
|
use warnings; |
|
|
9
|
|
|
|
|
12
|
|
|
|
9
|
|
|
|
|
281
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
35
|
use base qw(Exporter); |
|
|
9
|
|
|
|
|
31
|
|
|
|
9
|
|
|
|
|
910
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw(mkerror); |
|
9
|
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
1156
|
use Readonly; |
|
|
9
|
|
|
|
|
6574
|
|
|
|
9
|
|
|
|
|
495
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
9
|
|
|
9
|
|
2320
|
use overload bool => 'is_error', '==' => '_is_equal', '!=' => '_is_not_equal', '""' => '_stringify'; |
|
|
9
|
|
|
|
|
1830
|
|
|
|
9
|
|
|
|
|
46
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly our $DUPLICATE_ENTRY => 'DuplicateEntry'; |
|
15
|
|
|
|
|
|
|
Readonly our $NOT_FOUND => 'NotFound'; |
|
16
|
|
|
|
|
|
|
Readonly our $ALREADY_INACTIVE => 'AlreadyInactive'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Readonly::Hash our %ERROR_CODES => { |
|
19
|
|
|
|
|
|
|
$DUPLICATE_ENTRY => 4002, |
|
20
|
|
|
|
|
|
|
$NOT_FOUND => 4001, |
|
21
|
|
|
|
|
|
|
$ALREADY_INACTIVE => 4010, |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Readonly::Hash our %REVERSE_ERROR_CODES => map {$ERROR_CODES{$_} => $_} keys %ERROR_CODES; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Net::FreeIPA::Error is an error class for Net::FreeIPA. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Boolean logic and (non)-equal operator are overloaded using C method. |
|
31
|
|
|
|
|
|
|
(Use C<==> and C also for name/message, not C / C operators). |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 Public methods |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=over |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item mkerror |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
A C factory |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub mkerror |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
47
|
|
|
47
|
1
|
5530
|
return Net::FreeIPA::Error->new(@_); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item new |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Create new error instance from options, e.g. from a (decoded dereferenced) JSON response. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Arguments are handled by C. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub new |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
48
|
|
|
48
|
1
|
760
|
my $this = shift; |
|
60
|
48
|
|
33
|
|
|
195
|
my $class = ref($this) || $this; |
|
61
|
48
|
|
|
|
|
90
|
my $self = { |
|
62
|
|
|
|
|
|
|
__errattr => [], |
|
63
|
|
|
|
|
|
|
}; |
|
64
|
48
|
|
|
|
|
57
|
bless $self, $class; |
|
65
|
|
|
|
|
|
|
|
|
66
|
48
|
|
|
|
|
97
|
$self->set_error(@_); |
|
67
|
|
|
|
|
|
|
|
|
68
|
48
|
|
|
|
|
126
|
return $self; |
|
69
|
|
|
|
|
|
|
}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item set_error |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Process arguments to error |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item no args/undef: reset the error attribute |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item single argument string: convert to an C instance with message |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item single argument hasref/Error instance: make a copy |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item single argument/other: set Error message and save original in _orig attribute |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item options (more than one arg): set the options |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=back |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub set_error |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
55
|
|
|
55
|
1
|
54
|
my $self = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
55
|
|
|
|
|
53
|
my $nrargs = scalar @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
55
|
|
|
|
|
51
|
my %opts; |
|
98
|
55
|
100
|
|
|
|
135
|
if ($nrargs == 1) { |
|
|
|
100
|
|
|
|
|
|
|
99
|
10
|
|
|
|
|
13
|
my $err = shift; |
|
100
|
10
|
|
|
|
|
12
|
my $ref = ref($err); |
|
101
|
|
|
|
|
|
|
|
|
102
|
10
|
100
|
100
|
|
|
58
|
if($ref eq 'Net::FreeIPA::Error') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
2
|
%opts = map {$_ => $err->{$_}} @{$err->{__errattr}}; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
104
|
|
|
|
|
|
|
} elsif ($ref eq 'HASH') { |
|
105
|
2
|
|
|
|
|
14
|
%opts = %$err; |
|
106
|
|
|
|
|
|
|
} elsif (defined($err) && $ref eq '') { |
|
107
|
3
|
|
|
|
|
8
|
$opts{message} = $err; |
|
108
|
|
|
|
|
|
|
} elsif (defined($err)) { |
|
109
|
1
|
|
|
|
|
3
|
$opts{message} = "unknown error type $ref, see _orig attribute"; |
|
110
|
1
|
|
|
|
|
2
|
$opts{_orig} = $err; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
} elsif ($nrargs > 1) { |
|
113
|
35
|
|
|
|
|
79
|
%opts = @_; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Wipe current state |
|
118
|
|
|
|
|
|
|
# Do this after the %opts are build, to allow copies of itself |
|
119
|
55
|
|
|
|
|
44
|
foreach my $key (@{$self->{__errattr}}) { |
|
|
55
|
|
|
|
|
184
|
|
|
120
|
7
|
|
|
|
|
12
|
delete $self->{$key}; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
55
|
|
|
|
|
71
|
$self->{__errattr} = []; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# sort produces sorted __errattr |
|
125
|
55
|
|
|
|
|
130
|
foreach my $key (sort keys %opts) { |
|
126
|
44
|
|
|
|
|
54
|
$self->{$key} = $opts{$key}; |
|
127
|
44
|
|
|
|
|
36
|
push(@{$self->{__errattr}}, $key); |
|
|
44
|
|
|
|
|
87
|
|
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
55
|
|
|
|
|
83
|
return $self; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item is_error |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Test if this is an error or not. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
If an optiona l C argument is passed, |
|
138
|
|
|
|
|
|
|
test if error name or code is equal to C. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
A numerical type is compare to the code, a string is compare to the name or message |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
For a set of known errorcodes, a automatic reverse lookup is performed. |
|
143
|
|
|
|
|
|
|
When e.g. only the error name attribute is set, one can test using a known errorcode. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub is_error |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
137
|
|
|
137
|
1
|
215
|
my ($self, $type, $reverse_lookup) = @_; |
|
150
|
|
|
|
|
|
|
|
|
151
|
137
|
100
|
|
|
|
299
|
$reverse_lookup = 1 if ! defined($reverse_lookup); |
|
152
|
|
|
|
|
|
|
|
|
153
|
137
|
|
|
|
|
107
|
my $res; |
|
154
|
|
|
|
|
|
|
|
|
155
|
137
|
100
|
|
|
|
163
|
if(defined($type)) { |
|
156
|
53
|
|
|
|
|
42
|
my $revtype; |
|
157
|
|
|
|
|
|
|
|
|
158
|
53
|
100
|
|
|
|
183
|
if ($type =~ m/^\d+$/) { |
|
159
|
28
|
100
|
|
|
|
88
|
$revtype = $REVERSE_ERROR_CODES{$type} if (exists($REVERSE_ERROR_CODES{$type})); |
|
160
|
28
|
|
100
|
|
|
261
|
$res = exists($self->{code}) && ($self->{code} == $type); |
|
161
|
|
|
|
|
|
|
} else { |
|
162
|
25
|
100
|
|
|
|
73
|
$revtype = $ERROR_CODES{$type} if (exists($ERROR_CODES{$type})); |
|
163
|
25
|
|
66
|
|
|
296
|
$res = (exists($self->{name}) && ($self->{name} eq $type)) || (exists($self->{message}) && ($self->{message} eq $type)); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# If a reverse known error is found, and it is not yet an error, lookup the reverse |
|
167
|
|
|
|
|
|
|
# Disable the reverse-lookup here to avoid loop |
|
168
|
53
|
100
|
100
|
|
|
214
|
$res = $self->is_error($revtype, 0) if ($reverse_lookup && defined($revtype) && ! $res); |
|
|
|
|
100
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} else { |
|
170
|
84
|
|
66
|
|
|
230
|
$res = exists($self->{code}) || exists($self->{name}) || exists($self->{message}); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
137
|
100
|
|
|
|
396
|
return $res ? 1 : 0; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item is_duplicate |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Test if this is a DuplicateEntry error |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub is_duplicate |
|
183
|
|
|
|
|
|
|
{ |
|
184
|
4
|
|
|
4
|
1
|
16
|
my ($self) = @_; |
|
185
|
|
|
|
|
|
|
|
|
186
|
4
|
|
|
|
|
6
|
return $self->is_error($DUPLICATE_ENTRY); |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item is_already_inactive |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Test if this is a AlreadyInactive error |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub is_already_inactive |
|
196
|
|
|
|
|
|
|
{ |
|
197
|
4
|
|
|
4
|
1
|
24
|
my ($self) = @_; |
|
198
|
|
|
|
|
|
|
|
|
199
|
4
|
|
|
|
|
7
|
return $self->is_error($ALREADY_INACTIVE); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item is_not_found |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Test if this is a NotFound error |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub is_not_found |
|
210
|
|
|
|
|
|
|
{ |
|
211
|
4
|
|
|
4
|
1
|
19
|
my ($self) = @_; |
|
212
|
|
|
|
|
|
|
|
|
213
|
4
|
|
|
|
|
6
|
return $self->is_error($NOT_FOUND); |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# is_equal for overloading == |
|
217
|
|
|
|
|
|
|
# handle == undef (otherwise this would be $self->is_error) |
|
218
|
|
|
|
|
|
|
sub _is_equal |
|
219
|
|
|
|
|
|
|
{ |
|
220
|
|
|
|
|
|
|
# Use shift, looks like a 3rd argument (an empty string) is passed |
|
221
|
7
|
|
|
7
|
|
203
|
my $self = shift; |
|
222
|
7
|
|
|
|
|
7
|
my $othererror = shift; |
|
223
|
7
|
|
66
|
|
|
23
|
return defined($othererror) && $self->is_error($othererror); |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# inverse is_equal for overloading != |
|
227
|
|
|
|
|
|
|
sub _is_not_equal |
|
228
|
|
|
|
|
|
|
{ |
|
229
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
230
|
1
|
|
|
|
|
3
|
return ! $self->_is_equal(@_); |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# _stringify create string for stringification |
|
234
|
|
|
|
|
|
|
sub _stringify |
|
235
|
|
|
|
|
|
|
{ |
|
236
|
38
|
|
|
38
|
|
729
|
my $self = shift; |
|
237
|
|
|
|
|
|
|
|
|
238
|
38
|
100
|
|
|
|
53
|
if ($self->is_error()) { |
|
239
|
27
|
|
|
|
|
25
|
my @fields; |
|
240
|
27
|
|
|
|
|
40
|
foreach my $attr (qw(name code message)) { |
|
241
|
81
|
100
|
|
|
|
155
|
push(@fields, $self->{$attr}) if exists ($self->{$attr}); |
|
242
|
|
|
|
|
|
|
} |
|
243
|
27
|
|
|
|
|
122
|
return "Error ".join('/', @fields); |
|
244
|
|
|
|
|
|
|
} else { |
|
245
|
11
|
|
|
|
|
51
|
return "No error"; |
|
246
|
|
|
|
|
|
|
}; |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=pod |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=back |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; |