line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2014 - present MongoDB, Inc. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
4
|
|
|
|
|
|
|
# you may not use this file except in compliance with the License. |
5
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
10
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
13
|
|
|
|
|
|
|
# limitations under the License. |
14
|
|
|
|
|
|
|
|
15
|
70
|
|
|
70
|
|
517698
|
use strict; |
|
70
|
|
|
|
|
233
|
|
|
70
|
|
|
|
|
1921
|
|
16
|
70
|
|
|
70
|
|
340
|
use warnings; |
|
70
|
|
|
|
|
124
|
|
|
70
|
|
|
|
|
2345
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package MongoDB::Error; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ABSTRACT: MongoDB Driver Error classes |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Portions adapted from Throwable.pm by Ricardo Signes |
23
|
|
|
|
|
|
|
|
24
|
70
|
|
|
70
|
|
2777
|
use version; |
|
70
|
|
|
|
|
10767
|
|
|
70
|
|
|
|
|
364
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = 'v2.2.1'; |
27
|
|
|
|
|
|
|
|
28
|
70
|
|
|
70
|
|
8950
|
use Moo; |
|
70
|
|
|
|
|
70057
|
|
|
70
|
|
|
|
|
637
|
|
29
|
70
|
|
|
70
|
|
29282
|
use Carp; |
|
70
|
|
|
|
|
178
|
|
|
70
|
|
|
|
|
4470
|
|
30
|
70
|
|
|
|
|
1931
|
use MongoDB::_Types qw( |
31
|
|
|
|
|
|
|
ErrorStr |
32
|
70
|
|
|
70
|
|
29044
|
); |
|
70
|
|
|
|
|
291
|
|
33
|
70
|
|
|
|
|
445
|
use Types::Standard qw( |
34
|
|
|
|
|
|
|
ArrayRef |
35
|
|
|
|
|
|
|
Str |
36
|
70
|
|
|
70
|
|
82016
|
); |
|
70
|
|
|
|
|
162
|
|
37
|
70
|
|
|
70
|
|
58121
|
use Scalar::Util (); |
|
70
|
|
|
|
|
157
|
|
|
70
|
|
|
|
|
1134
|
|
38
|
70
|
|
|
70
|
|
32829
|
use Sub::Quote (); |
|
70
|
|
|
|
|
311848
|
|
|
70
|
|
|
|
|
1663
|
|
39
|
70
|
|
|
70
|
|
27780
|
use Safe::Isa; |
|
70
|
|
|
|
|
28593
|
|
|
70
|
|
|
|
|
10299
|
|
40
|
70
|
|
|
70
|
|
713
|
use Exporter 5.57 qw/import/; |
|
70
|
|
|
|
|
986
|
|
|
70
|
|
|
|
|
2510
|
|
41
|
70
|
|
|
70
|
|
32728
|
use namespace::clean -except => ['import']; |
|
70
|
|
|
|
|
675905
|
|
|
70
|
|
|
|
|
1960
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $ERROR_CODES; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
BEGIN { |
46
|
70
|
|
|
70
|
|
32807
|
$ERROR_CODES = { |
47
|
|
|
|
|
|
|
BAD_VALUE => 2, |
48
|
|
|
|
|
|
|
HOST_UNREACHABLE => 6, |
49
|
|
|
|
|
|
|
HOST_NOT_FOUND => 7, |
50
|
|
|
|
|
|
|
UNKNOWN_ERROR => 8, |
51
|
|
|
|
|
|
|
USER_NOT_FOUND => 11, |
52
|
|
|
|
|
|
|
ILLEGAL_OPERATION => 20, |
53
|
|
|
|
|
|
|
NAMESPACE_NOT_FOUND => 26, |
54
|
|
|
|
|
|
|
INDEX_NOT_FOUND => 27, |
55
|
|
|
|
|
|
|
CURSOR_NOT_FOUND => 43, |
56
|
|
|
|
|
|
|
EXCEEDED_TIME_LIMIT => 50, |
57
|
|
|
|
|
|
|
COMMAND_NOT_FOUND => 59, |
58
|
|
|
|
|
|
|
WRITE_CONCERN_ERROR => 64, |
59
|
|
|
|
|
|
|
NETWORK_TIMEOUT => 89, |
60
|
|
|
|
|
|
|
SHUTDOWN_IN_PROGRESS => 91, |
61
|
|
|
|
|
|
|
PRIMARY_STEPPED_DOWN => 189, |
62
|
|
|
|
|
|
|
SOCKET_EXCEPTION => 9001, |
63
|
|
|
|
|
|
|
NOT_MASTER => 10107, |
64
|
|
|
|
|
|
|
DUPLICATE_KEY => 11000, |
65
|
|
|
|
|
|
|
DUPLICATE_KEY_UPDATE => 11001, # legacy before 2.6 |
66
|
|
|
|
|
|
|
INTERRUPTED_AT_SHUTDOWN => 11600, |
67
|
|
|
|
|
|
|
INTERRUPTED_DUE_TO_REPL_STATE_CHANGE => 11602, |
68
|
|
|
|
|
|
|
DUPLICATE_KEY_CAPPED => 12582, # legacy before 2.6 |
69
|
|
|
|
|
|
|
UNRECOGNIZED_COMMAND => 13390, # mongos error before 2.4 |
70
|
|
|
|
|
|
|
NOT_MASTER_NO_SLAVE_OK => 13435, |
71
|
|
|
|
|
|
|
NOT_MASTER_OR_SECONDARY => 13436, |
72
|
|
|
|
|
|
|
CANT_OPEN_DB_IN_READ_LOCK => 15927, |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
70
|
|
|
70
|
|
600
|
use constant $ERROR_CODES; |
|
70
|
|
|
|
|
160
|
|
|
70
|
|
|
|
|
22433
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Export error codes for use by end-users; this is unusual for Moo, but |
79
|
|
|
|
|
|
|
# probably sufficiently helpful to justify it |
80
|
|
|
|
|
|
|
our @EXPORT = keys %$ERROR_CODES; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
our %_HORRIBLE_HACK; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use overload ( |
85
|
|
|
|
|
|
|
q{""} => sub { |
86
|
739
|
|
|
739
|
|
13838
|
my $self = shift; |
87
|
739
|
|
|
|
|
5717
|
return sprintf( "%s: %s", ref($self), $self->message ); |
88
|
|
|
|
|
|
|
}, |
89
|
70
|
|
|
|
|
823
|
fallback => 1 |
90
|
70
|
|
|
70
|
|
555
|
); |
|
70
|
|
|
|
|
153
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
has message => ( |
93
|
|
|
|
|
|
|
is => 'ro', |
94
|
|
|
|
|
|
|
isa => ErrorStr, |
95
|
|
|
|
|
|
|
default => 'unspecified error', |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has 'previous_exception' => ( |
99
|
|
|
|
|
|
|
is => 'ro', |
100
|
|
|
|
|
|
|
default => Sub::Quote::quote_sub(q< |
101
|
|
|
|
|
|
|
if (defined $MongoDB::Error::_HORRIBLE_HACK{ERROR}) { |
102
|
|
|
|
|
|
|
$MongoDB::Error::_HORRIBLE_HACK{ERROR} |
103
|
|
|
|
|
|
|
} elsif (defined $@ and (ref $@ or length $@)) { |
104
|
|
|
|
|
|
|
$@; |
105
|
|
|
|
|
|
|
} else { |
106
|
|
|
|
|
|
|
undef; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
>), |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
has error_labels => ( |
112
|
|
|
|
|
|
|
is => 'ro', |
113
|
|
|
|
|
|
|
isa => ArrayRef[Str], |
114
|
|
|
|
|
|
|
default => sub { [] }, |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub has_error_label { |
118
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $expected ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
0
|
return unless defined $self->error_labels; |
121
|
0
|
|
|
|
|
0
|
return grep { $_ eq $expected } @{ $self->error_labels }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub add_error_label { |
125
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $label ) = @_; |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
0
|
return if $self->has_error_label( $label ); |
128
|
0
|
|
|
|
|
0
|
push @{ $self->error_labels }, $label; |
|
0
|
|
|
|
|
0
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub throw { |
132
|
300
|
|
|
300
|
0
|
8304
|
my ($inv) = shift; |
133
|
|
|
|
|
|
|
|
134
|
300
|
50
|
|
|
|
1430
|
if (Scalar::Util::blessed($inv)) { |
135
|
0
|
0
|
|
|
|
0
|
Carp::confess "throw called on MongoDB::Error object with arguments" if @_; |
136
|
0
|
|
|
|
|
0
|
die $inv; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
300
|
|
|
|
|
1273
|
local $_HORRIBLE_HACK{ERROR} = $@; |
140
|
|
|
|
|
|
|
|
141
|
300
|
100
|
|
|
|
7106
|
my $throwable = @_ == 1 ? $inv->new( message => $_[0] ) : $inv->new(@_); |
142
|
|
|
|
|
|
|
|
143
|
300
|
|
|
|
|
14899
|
die $throwable; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# internal flag indicating if an operation should be retried when |
147
|
|
|
|
|
|
|
# an error occurs. |
148
|
0
|
|
|
0
|
|
0
|
sub _is_resumable { 1 } |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# internal flag for if this error type specifically can be retried regardless |
151
|
|
|
|
|
|
|
# of other state. See _is_retryable which contains the full retryable error |
152
|
|
|
|
|
|
|
# logic. |
153
|
0
|
|
|
0
|
|
0
|
sub __is_retryable_error { 0 } |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my @retryable_codes = ( |
156
|
|
|
|
|
|
|
MongoDB::Error::HOST_NOT_FOUND(), |
157
|
|
|
|
|
|
|
MongoDB::Error::HOST_UNREACHABLE(), |
158
|
|
|
|
|
|
|
MongoDB::Error::NETWORK_TIMEOUT(), |
159
|
|
|
|
|
|
|
MongoDB::Error::SHUTDOWN_IN_PROGRESS(), |
160
|
|
|
|
|
|
|
MongoDB::Error::PRIMARY_STEPPED_DOWN(), |
161
|
|
|
|
|
|
|
MongoDB::Error::SOCKET_EXCEPTION(), |
162
|
|
|
|
|
|
|
MongoDB::Error::NOT_MASTER(), |
163
|
|
|
|
|
|
|
MongoDB::Error::INTERRUPTED_AT_SHUTDOWN(), |
164
|
|
|
|
|
|
|
MongoDB::Error::INTERRUPTED_DUE_TO_REPL_STATE_CHANGE(), |
165
|
|
|
|
|
|
|
MongoDB::Error::NOT_MASTER_NO_SLAVE_OK(), |
166
|
|
|
|
|
|
|
MongoDB::Error::NOT_MASTER_OR_SECONDARY(), |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub _check_is_retryable_code { |
170
|
0
|
|
|
0
|
|
0
|
my $code = $_[-1]; |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
0
|
return 1 if grep { $code == $_ } @retryable_codes; |
|
0
|
|
|
|
|
0
|
|
173
|
0
|
|
|
|
|
0
|
return 0; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub _check_is_retryable_message { |
177
|
0
|
|
|
0
|
|
0
|
my $message = $_[-1]; |
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
0
|
return 0 unless defined $message; |
180
|
0
|
0
|
|
|
|
0
|
return 1 if $message =~ /(not master|node is recovering)/i; |
181
|
0
|
|
|
|
|
0
|
return 0; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# indicates if this error can be retried under retryable writes |
185
|
|
|
|
|
|
|
sub _is_retryable { |
186
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
0
|
if ( $self->$_can( 'result' ) ) { |
189
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_retryable_code( $self->result->last_code ); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
0
|
if ( $self->$_can( 'code' ) ) { |
193
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_retryable_code( $self->code ); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_retryable_message( $self->message ); |
197
|
|
|
|
|
|
|
|
198
|
0
|
0
|
0
|
|
|
0
|
if ( $self->$_isa( 'MongoDB::WriteConcernError' ) && $self->result->$_can( 'output' ) ) { |
199
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_retryable_code( $self->result->output->{writeConcernError}{code} ); |
200
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_retryable_message( $self->result->output->{writeConcernError}{message} ); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Defaults to 0 unless its a network exception |
204
|
0
|
|
|
|
|
0
|
return $self->__is_retryable_error; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
my @unknown_commit_codes = ( |
208
|
|
|
|
|
|
|
MongoDB::Error::EXCEEDED_TIME_LIMIT(), |
209
|
|
|
|
|
|
|
MongoDB::Error::WRITE_CONCERN_ERROR(), |
210
|
|
|
|
|
|
|
); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub _check_is_unknown_commit_code { |
213
|
0
|
|
|
0
|
|
0
|
my $code = $_[-1]; |
214
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
0
|
return 1 if grep { $code == $_ } @unknown_commit_codes; |
|
0
|
|
|
|
|
0
|
|
216
|
0
|
|
|
|
|
0
|
return 0; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub _is_unknown_commit_error { |
220
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
221
|
|
|
|
|
|
|
|
222
|
0
|
0
|
0
|
|
|
0
|
return 1 if $self->isa("MongoDB::ConnectionError") || $self->isa("MongoDB::SelectionError"); |
223
|
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
0
|
return 1 if $self->_is_retryable; |
225
|
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
0
|
if ( $self->$_can( 'result' ) ) { |
227
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_unknown_commit_code( $self->result->last_code ); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
0
|
if ( $self->$_can( 'code' ) ) { |
231
|
0
|
0
|
|
|
|
0
|
return 1 if _check_is_unknown_commit_code( $self->code ); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
0
|
return 0; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub _is_transient_transaction_error { |
238
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
239
|
0
|
0
|
0
|
|
|
0
|
return 1 if $self->isa("MongoDB::ConnectionError") || $self->isa("MongoDB::SelectionError"); |
240
|
0
|
|
|
|
|
0
|
return 0; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# Look for error code ILLEGAL_OPERATION and starts with "Transaction numbers" |
244
|
|
|
|
|
|
|
sub _is_storage_engine_not_retryable { |
245
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
246
|
0
|
0
|
|
|
|
0
|
if ( $self->$_can( 'code' ) ) { |
247
|
0
|
0
|
|
|
|
0
|
return 0 if $self->code != MongoDB::Error::ILLEGAL_OPERATION; |
248
|
|
|
|
|
|
|
} |
249
|
0
|
|
|
|
|
0
|
return index($self->message, "Transaction numbers", 0) == 0; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
253
|
|
|
|
|
|
|
# Subclasses with attributes included inline below |
254
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
package MongoDB::DatabaseError; |
257
|
70
|
|
|
70
|
|
79057
|
use Moo; |
|
70
|
|
|
|
|
204
|
|
|
70
|
|
|
|
|
642
|
|
258
|
70
|
|
|
|
|
553
|
use MongoDB::_Types qw( |
259
|
|
|
|
|
|
|
Numish |
260
|
70
|
|
|
70
|
|
28744
|
); |
|
70
|
|
|
|
|
179
|
|
261
|
70
|
|
|
70
|
|
74602
|
use namespace::clean; |
|
70
|
|
|
|
|
149
|
|
|
70
|
|
|
|
|
289
|
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
extends("MongoDB::Error"); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
has result => ( |
266
|
|
|
|
|
|
|
is => 'ro', |
267
|
|
|
|
|
|
|
does => 'MongoDB::Role::_DatabaseErrorThrower', |
268
|
|
|
|
|
|
|
required => 1, |
269
|
|
|
|
|
|
|
); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
has code => ( |
272
|
|
|
|
|
|
|
is => 'ro', |
273
|
|
|
|
|
|
|
isa => Numish, |
274
|
|
|
|
|
|
|
builder => '_build_code', |
275
|
|
|
|
|
|
|
); |
276
|
|
|
|
|
|
|
|
277
|
1
|
|
|
1
|
|
5070
|
sub _build_code { return MongoDB::Error::UNKNOWN_ERROR() } |
278
|
|
|
|
|
|
|
|
279
|
0
|
|
|
0
|
|
|
sub _is_resumable { 0 } |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
package MongoDB::DocumentError; |
282
|
|
|
|
|
|
|
|
283
|
70
|
|
|
70
|
|
22713
|
use Moo; |
|
70
|
|
|
|
|
156
|
|
|
70
|
|
|
|
|
308
|
|
284
|
70
|
|
|
70
|
|
20954
|
use Types::Standard qw(Any); |
|
70
|
|
|
|
|
215
|
|
|
70
|
|
|
|
|
550
|
|
285
|
70
|
|
|
70
|
|
52209
|
use namespace::clean; |
|
70
|
|
|
|
|
178
|
|
|
70
|
|
|
|
|
283
|
|
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
extends("MongoDB::Error"); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
has document => ( |
290
|
|
|
|
|
|
|
is => 'ro', |
291
|
|
|
|
|
|
|
isa => Any, |
292
|
|
|
|
|
|
|
required => 1, |
293
|
|
|
|
|
|
|
); |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
package MongoDB::UsageError; |
296
|
|
|
|
|
|
|
|
297
|
70
|
|
|
70
|
|
18722
|
use Moo; |
|
70
|
|
|
|
|
192
|
|
|
70
|
|
|
|
|
331
|
|
298
|
70
|
|
|
70
|
|
19584
|
use Types::Standard qw(Str); |
|
70
|
|
|
|
|
149
|
|
|
70
|
|
|
|
|
301
|
|
299
|
70
|
|
|
70
|
|
32533
|
use namespace::clean -except => 'meta'; |
|
70
|
|
|
|
|
151
|
|
|
70
|
|
|
|
|
786
|
|
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
extends("MongoDB::Error"); |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
use overload ( |
304
|
|
|
|
|
|
|
q{""} => sub { |
305
|
35
|
|
|
35
|
|
3220
|
my $self = shift; |
306
|
35
|
|
|
|
|
640
|
return sprintf( "%s: %s%s", ref($self), $self->message, $self->trace ); |
307
|
|
|
|
|
|
|
}, |
308
|
70
|
|
|
|
|
437
|
fallback => 1 |
309
|
70
|
|
|
70
|
|
21083
|
); |
|
70
|
|
|
|
|
137
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
has trace => ( |
312
|
|
|
|
|
|
|
is => 'ro', |
313
|
|
|
|
|
|
|
isa => Str, |
314
|
|
|
|
|
|
|
); |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
around BUILDARGS => sub { |
317
|
|
|
|
|
|
|
my $orig = shift; |
318
|
|
|
|
|
|
|
my $class = shift; |
319
|
|
|
|
|
|
|
my $args = $class->SUPER::BUILDARGS(@_); |
320
|
|
|
|
|
|
|
# start stack trace above where throw() is called (or |
321
|
|
|
|
|
|
|
# at the top of the stack), so it works like confess |
322
|
|
|
|
|
|
|
my $i = 0; |
323
|
|
|
|
|
|
|
while ( my @caller = caller($i) ) { |
324
|
|
|
|
|
|
|
$i++; |
325
|
|
|
|
|
|
|
last if $caller[0] eq "MongoDB::Error"; |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
local $Carp::CarpLevel = caller( $i + 1 ) ? $i + 1 : $i; |
328
|
|
|
|
|
|
|
$args->{trace} = Carp::longmess(''); |
329
|
|
|
|
|
|
|
return $args; |
330
|
|
|
|
|
|
|
}; |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
# Connection errors |
333
|
|
|
|
|
|
|
package MongoDB::ConnectionError; |
334
|
70
|
|
|
70
|
|
15545
|
use Moo; |
|
70
|
|
|
|
|
164
|
|
|
70
|
|
|
|
|
382
|
|
335
|
70
|
|
|
70
|
|
19605
|
use namespace::clean; |
|
70
|
|
|
|
|
261
|
|
|
70
|
|
|
|
|
275
|
|
336
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
337
|
|
|
|
|
|
|
|
338
|
0
|
|
|
0
|
|
|
sub _is_resumable { 1 } |
339
|
0
|
|
|
0
|
|
|
sub __is_retryable_error { 1 } |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
package MongoDB::HandshakeError; |
342
|
70
|
|
|
70
|
|
18436
|
use Moo; |
|
70
|
|
|
|
|
145
|
|
|
70
|
|
|
|
|
297
|
|
343
|
70
|
|
|
70
|
|
20659
|
use namespace::clean; |
|
70
|
|
|
|
|
189
|
|
|
70
|
|
|
|
|
345
|
|
344
|
|
|
|
|
|
|
extends 'MongoDB::ConnectionError'; |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
package MongoDB::NetworkError; |
347
|
70
|
|
|
70
|
|
19761
|
use Moo; |
|
70
|
|
|
|
|
184
|
|
|
70
|
|
|
|
|
300
|
|
348
|
70
|
|
|
70
|
|
22183
|
use namespace::clean; |
|
70
|
|
|
|
|
152
|
|
|
70
|
|
|
|
|
450
|
|
349
|
|
|
|
|
|
|
extends 'MongoDB::ConnectionError'; |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# Timeout errors |
352
|
|
|
|
|
|
|
package MongoDB::TimeoutError; |
353
|
70
|
|
|
70
|
|
17354
|
use Moo; |
|
70
|
|
|
|
|
135
|
|
|
70
|
|
|
|
|
290
|
|
354
|
70
|
|
|
70
|
|
21023
|
use namespace::clean; |
|
70
|
|
|
|
|
175
|
|
|
70
|
|
|
|
|
317
|
|
355
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
356
|
|
|
|
|
|
|
|
357
|
0
|
|
|
0
|
|
|
sub __is_retryable_error { 1 } |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
package MongoDB::ExecutionTimeout; |
360
|
70
|
|
|
70
|
|
20228
|
use Moo; |
|
70
|
|
|
|
|
168
|
|
|
70
|
|
|
|
|
321
|
|
361
|
70
|
|
|
70
|
|
24978
|
use namespace::clean; |
|
70
|
|
|
|
|
180
|
|
|
70
|
|
|
|
|
418
|
|
362
|
|
|
|
|
|
|
extends 'MongoDB::TimeoutError'; |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
package MongoDB::NetworkTimeout; |
365
|
70
|
|
|
70
|
|
17029
|
use Moo; |
|
70
|
|
|
|
|
147
|
|
|
70
|
|
|
|
|
2920
|
|
366
|
70
|
|
|
70
|
|
23599
|
use namespace::clean; |
|
70
|
|
|
|
|
144
|
|
|
70
|
|
|
|
|
1657
|
|
367
|
|
|
|
|
|
|
extends 'MongoDB::TimeoutError'; |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# Database errors |
370
|
|
|
|
|
|
|
package MongoDB::DuplicateKeyError; |
371
|
70
|
|
|
70
|
|
17123
|
use Moo; |
|
70
|
|
|
|
|
1452
|
|
|
70
|
|
|
|
|
318
|
|
372
|
70
|
|
|
70
|
|
23115
|
use namespace::clean; |
|
70
|
|
|
|
|
160
|
|
|
70
|
|
|
|
|
306
|
|
373
|
|
|
|
|
|
|
extends 'MongoDB::DatabaseError'; |
374
|
0
|
|
|
0
|
|
|
sub _build_code { return MongoDB::Error::DUPLICATE_KEY() } |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
package MongoDB::NotMasterError; |
377
|
70
|
|
|
70
|
|
18544
|
use Moo; |
|
70
|
|
|
|
|
173
|
|
|
70
|
|
|
|
|
1544
|
|
378
|
70
|
|
|
70
|
|
20564
|
use namespace::clean; |
|
70
|
|
|
|
|
171
|
|
|
70
|
|
|
|
|
316
|
|
379
|
|
|
|
|
|
|
extends 'MongoDB::DatabaseError'; |
380
|
0
|
|
|
0
|
|
|
sub _build_code { return MongoDB::Error::NOT_MASTER() } |
381
|
0
|
|
|
0
|
|
|
sub _is_resumable { 1 } |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
package MongoDB::WriteError; |
384
|
70
|
|
|
70
|
|
19312
|
use Moo; |
|
70
|
|
|
|
|
182
|
|
|
70
|
|
|
|
|
296
|
|
385
|
70
|
|
|
70
|
|
21947
|
use namespace::clean; |
|
70
|
|
|
|
|
190
|
|
|
70
|
|
|
|
|
284
|
|
386
|
|
|
|
|
|
|
extends 'MongoDB::DatabaseError'; |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
package MongoDB::WriteConcernError; |
389
|
70
|
|
|
70
|
|
17310
|
use Moo; |
|
70
|
|
|
|
|
147
|
|
|
70
|
|
|
|
|
286
|
|
390
|
70
|
|
|
70
|
|
21415
|
use namespace::clean; |
|
70
|
|
|
|
|
175
|
|
|
70
|
|
|
|
|
350
|
|
391
|
|
|
|
|
|
|
extends 'MongoDB::DatabaseError'; |
392
|
0
|
|
|
0
|
|
|
sub _build_code { return MongoDB::Error::WRITE_CONCERN_ERROR() } |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
# Other errors |
395
|
|
|
|
|
|
|
package MongoDB::AuthError; |
396
|
70
|
|
|
70
|
|
18999
|
use Moo; |
|
70
|
|
|
|
|
152
|
|
|
70
|
|
|
|
|
275
|
|
397
|
70
|
|
|
70
|
|
20539
|
use namespace::clean; |
|
70
|
|
|
|
|
162
|
|
|
70
|
|
|
|
|
320
|
|
398
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
package MongoDB::ConfigurationError; |
401
|
70
|
|
|
70
|
|
17315
|
use Moo; |
|
70
|
|
|
|
|
160
|
|
|
70
|
|
|
|
|
351
|
|
402
|
70
|
|
|
70
|
|
20297
|
use namespace::clean; |
|
70
|
|
|
|
|
178
|
|
|
70
|
|
|
|
|
287
|
|
403
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
package MongoDB::CursorNotFoundError; |
406
|
70
|
|
|
70
|
|
17122
|
use Moo; |
|
70
|
|
|
|
|
1598
|
|
|
70
|
|
|
|
|
352
|
|
407
|
70
|
|
|
70
|
|
20686
|
use namespace::clean; |
|
70
|
|
|
|
|
174
|
|
|
70
|
|
|
|
|
338
|
|
408
|
|
|
|
|
|
|
extends 'MongoDB::DatabaseError'; |
409
|
0
|
|
|
0
|
|
|
sub _build_code { return MongoDB::Error::CURSOR_NOT_FOUND() } |
410
|
0
|
|
|
0
|
|
|
sub _is_resumable { 1 } |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
package MongoDB::DecodingError; |
413
|
70
|
|
|
70
|
|
21580
|
use Moo; |
|
70
|
|
|
|
|
183
|
|
|
70
|
|
|
|
|
303
|
|
414
|
70
|
|
|
70
|
|
20588
|
use namespace::clean; |
|
70
|
|
|
|
|
151
|
|
|
70
|
|
|
|
|
1846
|
|
415
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
package MongoDB::GridFSError; |
418
|
70
|
|
|
70
|
|
17528
|
use Moo; |
|
70
|
|
|
|
|
161
|
|
|
70
|
|
|
|
|
320
|
|
419
|
70
|
|
|
70
|
|
21603
|
use namespace::clean; |
|
70
|
|
|
|
|
148
|
|
|
70
|
|
|
|
|
310
|
|
420
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
package MongoDB::InternalError; |
423
|
70
|
|
|
70
|
|
17268
|
use Moo; |
|
70
|
|
|
|
|
149
|
|
|
70
|
|
|
|
|
339
|
|
424
|
70
|
|
|
70
|
|
22876
|
use namespace::clean; |
|
70
|
|
|
|
|
136
|
|
|
70
|
|
|
|
|
351
|
|
425
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
package MongoDB::ProtocolError; |
428
|
70
|
|
|
70
|
|
18107
|
use Moo; |
|
70
|
|
|
|
|
188
|
|
|
70
|
|
|
|
|
286
|
|
429
|
70
|
|
|
70
|
|
20722
|
use namespace::clean; |
|
70
|
|
|
|
|
2760
|
|
|
70
|
|
|
|
|
283
|
|
430
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
package MongoDB::SelectionError; |
433
|
70
|
|
|
70
|
|
19672
|
use Moo; |
|
70
|
|
|
|
|
182
|
|
|
70
|
|
|
|
|
336
|
|
434
|
70
|
|
|
70
|
|
20111
|
use namespace::clean; |
|
70
|
|
|
|
|
158
|
|
|
70
|
|
|
|
|
1644
|
|
435
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
package MongoDB::InvalidOperationError; |
438
|
70
|
|
|
70
|
|
18473
|
use Moo; |
|
70
|
|
|
|
|
1504
|
|
|
70
|
|
|
|
|
2721
|
|
439
|
70
|
|
|
70
|
|
23163
|
use namespace::clean; |
|
70
|
|
|
|
|
1447
|
|
|
70
|
|
|
|
|
1794
|
|
440
|
|
|
|
|
|
|
extends 'MongoDB::Error'; |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
443
|
|
|
|
|
|
|
# Private error classes |
444
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
445
|
|
|
|
|
|
|
package MongoDB::_CommandSizeError; |
446
|
70
|
|
|
70
|
|
18731
|
use Moo; |
|
70
|
|
|
|
|
145
|
|
|
70
|
|
|
|
|
1549
|
|
447
|
70
|
|
|
|
|
412
|
use MongoDB::_Types qw( |
448
|
|
|
|
|
|
|
Intish |
449
|
70
|
|
|
70
|
|
20693
|
); |
|
70
|
|
|
|
|
135
|
|
450
|
70
|
|
|
70
|
|
74092
|
use namespace::clean; |
|
70
|
|
|
|
|
143
|
|
|
70
|
|
|
|
|
272
|
|
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
extends("MongoDB::Error"); |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
has size => ( |
455
|
|
|
|
|
|
|
is => 'ro', |
456
|
|
|
|
|
|
|
isa => Intish, |
457
|
|
|
|
|
|
|
required => 1, |
458
|
|
|
|
|
|
|
); |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
1; |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
=pod |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=encoding UTF-8 |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
=head1 NAME |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
MongoDB::Error - MongoDB Driver Error classes |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=head1 VERSION |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
version v2.2.1 |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
=head1 SYNOPSIS |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
use MongoDB::Error; |
477
|
|
|
|
|
|
|
MongoDB::Error->throw("a generic error"); |
478
|
|
|
|
|
|
|
MongoDB::DatabaseError->throw( |
479
|
|
|
|
|
|
|
message => $string, |
480
|
|
|
|
|
|
|
result => $hashref, |
481
|
|
|
|
|
|
|
); |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
=head1 DESCRIPTION |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
This class defines a hierarchy of exception objects. |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=head1 USAGE |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
Unless otherwise explicitly documented, all driver methods throw exceptions if |
490
|
|
|
|
|
|
|
an error occurs. |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
To catch and handle errors, the L and L modules |
493
|
|
|
|
|
|
|
are recommended: |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
use Try::Tiny; |
496
|
|
|
|
|
|
|
use Safe::Isa; # provides $_isa |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
try { |
499
|
|
|
|
|
|
|
$coll->insert( $doc ) |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
catch { |
502
|
|
|
|
|
|
|
if ( $_->$_isa("MongoDB::DuplicateKeyError" ) ) { |
503
|
|
|
|
|
|
|
... |
504
|
|
|
|
|
|
|
} |
505
|
|
|
|
|
|
|
else { |
506
|
|
|
|
|
|
|
... |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
}; |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
To retry failures automatically, consider using L. |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=head1 EXCEPTION HIERARCHY |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
MongoDB::Error |
515
|
|
|
|
|
|
|
| |
516
|
|
|
|
|
|
|
|->MongoDB::AuthError |
517
|
|
|
|
|
|
|
| |
518
|
|
|
|
|
|
|
|->MongoDB::ConnectionError |
519
|
|
|
|
|
|
|
| | |
520
|
|
|
|
|
|
|
| |->MongoDB::HandshakeError |
521
|
|
|
|
|
|
|
| | |
522
|
|
|
|
|
|
|
| |->MongoDB::NetworkError |
523
|
|
|
|
|
|
|
| |
524
|
|
|
|
|
|
|
|->MongoDB::ConfigurationError |
525
|
|
|
|
|
|
|
| |
526
|
|
|
|
|
|
|
|->MongoDB::DatabaseError |
527
|
|
|
|
|
|
|
| | |
528
|
|
|
|
|
|
|
| |->MongoDB::CursorNotFoundError |
529
|
|
|
|
|
|
|
| | |
530
|
|
|
|
|
|
|
| |->MongoDB::DuplicateKeyError |
531
|
|
|
|
|
|
|
| | |
532
|
|
|
|
|
|
|
| |->MongoDB::NotMasterError |
533
|
|
|
|
|
|
|
| | |
534
|
|
|
|
|
|
|
| |->MongoDB::WriteError |
535
|
|
|
|
|
|
|
| | |
536
|
|
|
|
|
|
|
| |->MongoDB::WriteConcernError |
537
|
|
|
|
|
|
|
| |
538
|
|
|
|
|
|
|
|->MongoDB::DecodingError |
539
|
|
|
|
|
|
|
| |
540
|
|
|
|
|
|
|
|->MongoDB::DocumentError |
541
|
|
|
|
|
|
|
| |
542
|
|
|
|
|
|
|
|->MongoDB::GridFSError |
543
|
|
|
|
|
|
|
| |
544
|
|
|
|
|
|
|
|->MongoDB::InternalError |
545
|
|
|
|
|
|
|
| |
546
|
|
|
|
|
|
|
|->MongoDB::InvalidOperationError |
547
|
|
|
|
|
|
|
| |
548
|
|
|
|
|
|
|
|->MongoDB::ProtocolError |
549
|
|
|
|
|
|
|
| |
550
|
|
|
|
|
|
|
|->MongoDB::SelectionError |
551
|
|
|
|
|
|
|
| |
552
|
|
|
|
|
|
|
|->MongoDB::TimeoutError |
553
|
|
|
|
|
|
|
| | |
554
|
|
|
|
|
|
|
| |->MongoDB::ExecutionTimeout |
555
|
|
|
|
|
|
|
| | |
556
|
|
|
|
|
|
|
| |->MongoDB::NetworkTimeout |
557
|
|
|
|
|
|
|
| |
558
|
|
|
|
|
|
|
|->MongoDB::UsageError |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
All classes inherit from C. |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
All error classes have the attribute: |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
=over 4 |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
=item * |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
message — a text representation of the error |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
=back |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
=head2 MongoDB::AuthError |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
This error indicates a problem with authentication, either in the underlying |
575
|
|
|
|
|
|
|
mechanism or a problem authenticating with the server. |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
=head2 MongoDB::ConnectionError |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
Errors related to network connections. |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
=head3 MongoDB::HandshakeError |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
This error is thrown when a connection has been made, but SSL or authentication |
584
|
|
|
|
|
|
|
handshakes fail. |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
=head3 MongoDB::NetworkError |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
This error is thrown when a socket error occurs, when the wrong number of bytes |
589
|
|
|
|
|
|
|
are read, or other wire-related errors occur. |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=head2 MongoDB::ConfigurationError |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
This error is thrown when there is a configuration error between the MongoDB |
594
|
|
|
|
|
|
|
deployment and the configuration of the client, such as when trying to use |
595
|
|
|
|
|
|
|
explicit sessions on a MongoDB < 3.6 |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
=head2 MongoDB::CursorNotFoundError |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
This error indicates that a cursor timed out on a server. |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
=head2 MongoDB::DatabaseError |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
Errors related to database operations. Specifically, when an error of this type |
604
|
|
|
|
|
|
|
occurs, the driver has received an error condition from the server. |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
Attributes include: |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=over 4 |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=item * |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
result — response from a database command; this must implement the C method |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=item * |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
code — numeric error code; see L; if no code was provided by the database, the C code will be substituted instead |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
=back |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
=head3 MongoDB::DuplicateKeyError |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
This error indicates that a write attempted to create a document with a |
623
|
|
|
|
|
|
|
duplicate key in a collection with a unique index. The C attribute is |
624
|
|
|
|
|
|
|
a result object. |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=head3 MongoDB::NotMasterError |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
This error indicates that a write or other state-modifying operation was |
629
|
|
|
|
|
|
|
attempted on a server that was not a primary. The C attribute is |
630
|
|
|
|
|
|
|
a L object. |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=head3 MongoDB::WriteError |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
Errors indicating failure of a write command. The C attribute is |
635
|
|
|
|
|
|
|
a result object. |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=head3 MongoDB::WriteConcernError |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
Errors indicating failure of a write concern. The C attribute is a |
640
|
|
|
|
|
|
|
result object. |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
=head2 MongoDB::DecodingError |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
This error indicates a problem during BSON decoding; it wraps |
645
|
|
|
|
|
|
|
the error provided by the underlying BSON encoder. Note: Encoding errors |
646
|
|
|
|
|
|
|
will be thrown as a L. |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=head2 MongoDB::DocumentError |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
This error indicates a problem with a document to be inserted or replaced into |
651
|
|
|
|
|
|
|
the database, or used as an update document. |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
Attributes include: |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
=over 4 |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=item * |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
document — the document that caused the error |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
=back |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
=head2 MongoDB::GridFSError |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Errors related to GridFS operations, such a corrupted file. |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
=head2 MongoDB::InternalError |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
Errors that indicate problems in the driver itself, typically when something |
670
|
|
|
|
|
|
|
unexpected is detected. These should be reported as potential bugs. |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
=head2 MongoDB::ProtocolError |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
Errors related to the MongoDB wire protocol, typically problems parsing a |
675
|
|
|
|
|
|
|
database response packet. |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=head2 MongoDB::SelectionError |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
When server selection fails for a given operation, this is thrown. For example, |
680
|
|
|
|
|
|
|
attempting a write when no primary is available or reading with a specific mode |
681
|
|
|
|
|
|
|
and tag set and no servers match. |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
=head2 MongoDB::TimeoutError |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
These errors indicate a user-specified timeout has been exceeded. |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
=head3 MongoDB::ExecutionTimeout |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
This error is thrown when a query or command fails because C has |
690
|
|
|
|
|
|
|
been reached. The C attribute is a L object. |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=head3 MongoDB::NetworkTimeout |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
This error is thrown when a network operation exceeds a timeout, typically |
695
|
|
|
|
|
|
|
C or C. |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
=head2 MongoDB::UsageError |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
Indicates invalid arguments or configuration options. Not all usage errors |
700
|
|
|
|
|
|
|
will throw this — only ones originating directly from the MongoDB::* library |
701
|
|
|
|
|
|
|
files. Some type and usage errors will originate from the L |
702
|
|
|
|
|
|
|
library if the objects are used incorrectly. |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
Also used to indicate usage errors for transaction commands. |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=head1 ERROR CODES |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
The following error code constants are automatically exported by this module. |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
BAD_VALUE => 2, |
711
|
|
|
|
|
|
|
UNKNOWN_ERROR => 8, |
712
|
|
|
|
|
|
|
NAMESPACE_NOT_FOUND => 26, |
713
|
|
|
|
|
|
|
EXCEEDED_TIME_LIMIT => 50, |
714
|
|
|
|
|
|
|
COMMAND_NOT_FOUND => 59, |
715
|
|
|
|
|
|
|
WRITE_CONCERN_ERROR => 64, |
716
|
|
|
|
|
|
|
NOT_MASTER => 10107, |
717
|
|
|
|
|
|
|
DUPLICATE_KEY => 11000, |
718
|
|
|
|
|
|
|
DUPLICATE_KEY_UPDATE => 11001, # legacy before 2.6 |
719
|
|
|
|
|
|
|
DUPLICATE_KEY_CAPPED => 12582, # legacy before 2.6 |
720
|
|
|
|
|
|
|
UNRECOGNIZED_COMMAND => 13390, # mongos error before 2.4 |
721
|
|
|
|
|
|
|
NOT_MASTER_NO_SLAVE_OK => 13435, |
722
|
|
|
|
|
|
|
NOT_MASTER_OR_SECONDARY => 13436, |
723
|
|
|
|
|
|
|
CANT_OPEN_DB_IN_READ_LOCK => 15927, |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
This is a very, very small subset of error codes possible from the server, |
726
|
|
|
|
|
|
|
but covers some of the more common ones seen by drivers. |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
B: |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
=over 4 |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
=item * |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
Only C objects have a C attribute. |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
=item * |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
The database uses multiple write concern error codes. The driver maps them all to WRITE_CONCERN_ERROR for consistency and convenience. |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
=back |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
=head1 ERROR LABELS |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
From MongoDB 4.0 onwards, errors may contain an error labels field. This field |
745
|
|
|
|
|
|
|
is populated for extra information from either the server or the driver, |
746
|
|
|
|
|
|
|
depending on the error. |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
Known error labels include (but are not limited to): |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=over 4 |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
=item * |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
C - added when network errors are encountered inside a transaction. |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
=item * |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
C - added when a transaction commit may not have been able to satisfy the provided write concern. |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=back |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
=head1 AUTHORS |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
=over 4 |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
=item * |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
David Golden |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
=item * |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
Rassi |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
=item * |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
Mike Friedman |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
=item * |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
Kristina Chodorow |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
=item * |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
Florian Ragwitz |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
=back |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
This software is Copyright (c) 2019 by MongoDB, Inc. |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
This is free software, licensed under: |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
=cut |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
__END__ |