| 1 | # Copyright 2016 - 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 | 60 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 16 | 60 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 17 | package MongoDB::Role::_DatabaseErrorThrower; | ||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||
| 19 | # MongoDB interface for providing the last database error | ||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | 60 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 22 | 60 | our $VERSION = 'v2.2.2'; | |||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | 60 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | 60 | ▶ | use MongoDB::Error; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | 60 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | 60 | requires qw/last_errmsg last_code last_wtimeout last_error_labels/; | |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | 60 | my $ANY_DUP_KEY = [ DUPLICATE_KEY, DUPLICATE_KEY_UPDATE, DUPLICATE_KEY_CAPPED ]; | |||||||||||||||||||||||||||||||||||||||
| 33 | 60 | my $ANY_NOT_MASTER = [ NOT_MASTER, NOT_MASTER_NO_SLAVE_OK, NOT_MASTER_OR_SECONDARY ]; | |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||
| 35 | # analyze last_errmsg and last_code and throw an appropriate | ||||||||||||||||||||||||||||||||||||||||
| 36 | # error message. | ||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _throw_database_error { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw_database_error: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ( $self, $error_class ) = @_; | |||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $error_class ||= "MongoDB::DatabaseError"; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error_class ||= "MongoDB::DatabaseError"
MC/DC0%0/1
$error_class ||= "MongoDB::DatabaseError"
$error_class
Truth table0%0/2
A
A= $error_class
| |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $err = $self->last_errmsg; | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $code = $self->last_code; | |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $error_labels = $self->last_error_labels; | |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( grep { $code == $_ } @$ANY_NOT_MASTER || $err =~ /^(?:not master|node is recovering)/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
@$ANY_NOT_MASTER || $err =~ /^(?:not master|node is recovering)/
MC/DC0%0/2
@$ANY_NOT_MASTER || $err =~ /^(?:not master|node is recovering)/
@$ANY_NOT_MASTER
$err =~ /^(?:not master|node is recovering)/
Truth table0%0/3
A || B
A= @$ANY_NOT_MASTERB= $err =~ /^(?:not master|node is recovering)/
| |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $error_class = "MongoDB::NotMasterError"; | |||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | elsif ( grep { $code == $_ } @$ANY_DUP_KEY ) { | |||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $error_class = "MongoDB::DuplicateKeyError"; | |||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||
| 51 | elsif ( $code == CURSOR_NOT_FOUND ) { | ||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $error_class = "MongoDB::CursorNotFoundError"; | |||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||
| 54 | elsif ( $self->last_wtimeout ) { | ||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $error_class = "MongoDB::WriteConcernError"; | |||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | $error_class->throw( | ||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | result => $self, | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$code || 8
MC/DC0%0/1
$code || 8
$code
Truth table0%0/2
A
A= $code
| |||||||||||||||||||||||||||||||||||||||||
| 60 | code => $code || UNKNOWN_ERROR, | ||||||||||||||||||||||||||||||||||||||||
| 61 | error_labels => $error_labels, | ||||||||||||||||||||||||||||||||||||||||
| 62 | ( length($err) ? ( message => $err ) : () ), | ||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||
| 67 | 60 | 1; | |||||||||||||||||||||||||||||||||||||||