From 69f5d3cdcb993f89904eb0452113b61f907626c6 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Thu, 9 Apr 2020 10:43:48 +0430 Subject: [PATCH 01/10] All errors code in mongodb generated from https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml --- src/ErrorCodes.php | 380 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 380 insertions(+) create mode 100644 src/ErrorCodes.php diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php new file mode 100644 index 000000000..513bfa976 --- /dev/null +++ b/src/ErrorCodes.php @@ -0,0 +1,380 @@ + +*/ + +class ErrorCodes { + + const OK = 0; + const InternalError = 1; + const BadValue = 2; + const OBSOLETE_DuplicateKey = 3; + const NoSuchKey = 4; + const GraphContainsCycle = 5; + const HostUnreachable = 6; + const HostNotFound = 7; + const UnknownError = 8; + const FailedToParse = 9; + const CannotMutateObject = 10; + const UserNotFound = 11; + const UnsupportedFormat = 12; + const Unauthorized = 13; + const TypeMismatch = 14; + const Overflow = 15; + const InvalidLength = 16; + const ProtocolError = 17; + const AuthenticationFailed = 18; + const CannotReuseObject = 19; + const IllegalOperation = 20; + const EmptyArrayOperation = 21; + const InvalidBSON = 22; + const AlreadyInitialized = 23; + const LockTimeout = 24; + const RemoteValidationError = 25; + const NamespaceNotFound = 26; + const IndexNotFound = 27; + const PathNotViable = 28; + const NonExistentPath = 29; + const InvalidPath = 30; + const RoleNotFound = 31; + const RolesNotRelated = 32; + const PrivilegeNotFound = 33; + const CannotBackfillArray = 34; + const UserModificationFailed = 35; + const RemoteChangeDetected = 36; + const FileRenameFailed = 37; + const FileNotOpen = 38; + const FileStreamFailed = 39; + const ConflictingUpdateOperators = 40; + const FileAlreadyOpen = 41; + const LogWriteFailed = 42; + const CursorNotFound = 43; + const UserDataInconsistent = 45; + const LockBusy = 46; + const NoMatchingDocument = 47; + const NamespaceExists = 48; + const InvalidRoleModification = 49; + const MaxTimeMSExpired = 50; + const ManualInterventionRequired = 51; + const DollarPrefixedFieldName = 52; + const InvalidIdField = 53; + const NotSingleValueField = 54; + const InvalidDBRef = 55; + const EmptyFieldName = 56; + const DottedFieldName = 57; + const RoleModificationFailed = 58; + const CommandNotFound = 59; + const OBSOLETE_DatabaseNotFound = 60; + const ShardKeyNotFound = 61; + const OplogOperationUnsupported = 62; + const StaleShardVersion = 63; + const WriteConcernFailed = 64; + const MultipleErrorsOccurred = 65; + const ImmutableField = 66; + const CannotCreateIndex = 67; + const IndexAlreadyExists = 68; + const AuthSchemaIncompatible = 69; + const ShardNotFound = 70; + const ReplicaSetNotFound = 71; + const InvalidOptions = 72; + const InvalidNamespace = 73; + const NodeNotFound = 74; + const WriteConcernLegacyOK = 75; + const NoReplicationEnabled = 76; + const OperationIncomplete = 77; + const CommandResultSchemaViolation = 78; + const UnknownReplWriteConcern = 79; + const RoleDataInconsistent = 80; + const NoMatchParseContext = 81; + const NoProgressMade = 82; + const RemoteResultsUnavailable = 83; + const DuplicateKeyValue = 84; + const IndexOptionsConflict = 85; + const IndexKeySpecsConflict = 86; + const CannotSplit = 87; + const SplitFailed_OBSOLETE = 88; + const NetworkTimeout = 89; + const CallbackCanceled = 90; + const ShutdownInProgress = 91; + const SecondaryAheadOfPrimary = 92; + const InvalidReplicaSetConfig = 93; + const NotYetInitialized = 94; + const NotSecondary = 95; + const OperationFailed = 96; + const NoProjectionFound = 97; + const DBPathInUse = 98; + const UnsatisfiableWriteConcern = 100; + const OutdatedClient = 101; + const IncompatibleAuditMetadata = 102; + const NewReplicaSetConfigurationIncompatible = 103; + const NodeNotElectable = 104; + const IncompatibleShardingMetadata = 105; + const DistributedClockSkewed = 106; + const LockFailed = 107; + const InconsistentReplicaSetNames = 108; + const ConfigurationInProgress = 109; + const CannotInitializeNodeWithData = 110; + const NotExactValueField = 111; + const WriteConflict = 112; + const InitialSyncFailure = 113; + const InitialSyncOplogSourceMissing = 114; + const CommandNotSupported = 115; + const DocTooLargeForCapped = 116; + const ConflictingOperationInProgress = 117; + const NamespaceNotSharded = 118; + const InvalidSyncSource = 119; + const OplogStartMissing = 120; + const DocumentValidationFailure = 121; + const OBSOLETE_ReadAfterOptimeTimeout = 122; + const NotAReplicaSet = 123; + const IncompatibleElectionProtocol = 124; + const CommandFailed = 125; + const RPCProtocolNegotiationFailed = 126; + const UnrecoverableRollbackError = 127; + const LockNotFound = 128; + const LockStateChangeFailed = 129; + const SymbolNotFound = 130; + const RLPInitializationFailed = 131; # Removed in 4.2 + const OBSOLETE_ConfigServersInconsistent = 132; + const FailedToSatisfyReadPreference = 133; + const ReadConcernMajorityNotAvailableYet = 134; + const StaleTerm = 135; + const CappedPositionLost = 136; + const IncompatibleShardingConfigVersion = 137; + const RemoteOplogStale = 138; + const JSInterpreterFailure = 139; + const InvalidSSLConfiguration = 140; + const SSLHandshakeFailed = 141; + const JSUncatchableError = 142; + const CursorInUse = 143; + const IncompatibleCatalogManager = 144; + const PooledConnectionsDropped = 145; + const ExceededMemoryLimit = 146; + const ZLibError = 147; + const ReadConcernMajorityNotEnabled = 148; + const NoConfigMaster = 149; + const StaleEpoch = 150; + const OperationCannotBeBatched = 151; + const OplogOutOfOrder = 152; + const ChunkTooBig = 153; + const InconsistentShardIdentity = 154; + const CannotApplyOplogWhilePrimary = 155; + const OBSOLETE_NeedsDocumentMove = 156; + const CanRepairToDowngrade = 157; + const MustUpgrade = 158; + const DurationOverflow = 159; + const MaxStalenessOutOfRange = 160; + const IncompatibleCollationVersion = 161; + const CollectionIsEmpty = 162; + const ZoneStillInUse = 163; + const InitialSyncActive = 164; + const ViewDepthLimitExceeded = 165; + const CommandNotSupportedOnView = 166; + const OptionNotSupportedOnView = 167; + const InvalidPipelineOperator = 168; + const CommandOnShardedViewNotSupportedOnMongod = 169; + const TooManyMatchingDocuments = 170; + const CannotIndexParallelArrays = 171; + const TransportSessionClosed = 172; + const TransportSessionNotFound = 173; + const TransportSessionUnknown = 174; + const QueryPlanKilled = 175; + const FileOpenFailed = 176; + const ZoneNotFound = 177; + const RangeOverlapConflict = 178; + const WindowsPdhError = 179; + const BadPerfCounterPath = 180; + const AmbiguousIndexKeyPattern = 181; + const InvalidViewDefinition = 182; + const ClientMetadataMissingField = 183; + const ClientMetadataAppNameTooLarge = 184; + const ClientMetadataDocumentTooLarge = 185; + const ClientMetadataCannotBeMutated = 186; + const LinearizableReadConcernError = 187; + const IncompatibleServerVersion = 188; + const PrimarySteppedDown = 189; + const MasterSlaveConnectionFailure = 190; + const OBSOLETE_BalancerLostDistributedLock = 191; + const FailPointEnabled = 192; + const NoShardingEnabled = 193; + const BalancerInterrupted = 194; + const ViewPipelineMaxSizeExceeded = 195; + const InvalidIndexSpecificationOption = 197; + const OBSOLETE_ReceivedOpReplyMessage = 198; + const ReplicaSetMonitorRemoved = 199; + const ChunkRangeCleanupPending = 200; + const CannotBuildIndexKeys = 201; + const NetworkInterfaceExceededTimeLimit = 202; + const ShardingStateNotInitialized = 203; + const TimeProofMismatch = 204; + const ClusterTimeFailsRateLimiter = 205; + const NoSuchSession = 206; + const InvalidUUID = 207; + const TooManyLocks = 208; + const StaleClusterTime = 209; + const CannotVerifyAndSignLogicalTime = 210; + const KeyNotFound = 211; + const IncompatibleRollbackAlgorithm = 212; + const DuplicateSession = 213; + const AuthenticationRestrictionUnmet = 214; + const DatabaseDropPending = 215; + const ElectionInProgress = 216; + const IncompleteTransactionHistory = 217; + const UpdateOperationFailed = 218; + const FTDCPathNotSet = 219; + const FTDCPathAlreadySet = 220; + const IndexModified = 221; + const CloseChangeStream = 222; + const IllegalOpMsgFlag = 223; + const QueryFeatureNotAllowed = 224; + const TransactionTooOld = 225; + const AtomicityFailure = 226; + const CannotImplicitlyCreateCollection = 227; + const SessionTransferIncomplete = 228; + const MustDowngrade = 229; + const DNSHostNotFound = 230; + const DNSProtocolError = 231; + const MaxSubPipelineDepthExceeded = 232; + const TooManyDocumentSequences = 233; + const RetryChangeStream = 234; + const InternalErrorNotSupported = 235; + const ForTestingErrorExtraInfo = 236; + const CursorKilled = 237; + const NotImplemented = 238; + const SnapshotTooOld = 239; + const DNSRecordTypeMismatch = 240; + const ConversionFailure = 241; + const CannotCreateCollection = 242; + const IncompatibleWithUpgradedServer = 243; + const NOT_YET_AVAILABLE_TransactionAborted = 244; + const BrokenPromise = 245; + const SnapshotUnavailable = 246; + const ProducerConsumerQueueBatchTooLarge = 247; + const ProducerConsumerQueueEndClosed = 248; + const StaleDbVersion = 249; + const StaleChunkHistory = 250; + const NoSuchTransaction = 251; + const ReentrancyNotAllowed = 252; + const FreeMonHttpInFlight = 253; + const FreeMonHttpTemporaryFailure = 254; + const FreeMonHttpPermanentFailure = 255; + const TransactionCommitted = 256; + const TransactionTooLarge = 257; + const UnknownFeatureCompatibilityVersion = 258; + const KeyedExecutorRetry = 259; + const InvalidResumeToken = 260; + const TooManyLogicalSessions = 261; + const ExceededTimeLimit = 262; + const OperationNotSupportedInTransaction = 263; + const TooManyFilesOpen = 264; + const OrphanedRangeCleanUpFailed = 265; + const FailPointSetFailed = 266; + const PreparedTransactionInProgress = 267; + const CannotBackup = 268; + const DataModifiedByRepair = 269; + const RepairedReplicaSetNode = 270; + const JSInterpreterFailureWithStack = 271; + const MigrationConflict = 272; + const ProducerConsumerQueueProducerQueueDepthExceeded = 273; + const ProducerConsumerQueueConsumed = 274; + const ExchangePassthrough = 275; + const IndexBuildAborted = 276; + const AlarmAlreadyFulfilled = 277; + const UnsatisfiableCommitQuorum = 278; + const ClientDisconnect = 279; + const ChangeStreamFatalError = 280; + const TransactionCoordinatorSteppingDown = 281; + const TransactionCoordinatorReachedAbortDecision = 282; + const WouldChangeOwningShard = 283; + const ForTestingErrorExtraInfoWithExtraInfoInNamespace = 284; + const IndexBuildAlreadyInProgress = 285; + const ChangeStreamHistoryLost = 286; + const TransactionCoordinatorDeadlineTaskCanceled = 287; + const ChecksumMismatch = 288; + const WaitForMajorityServiceEarlierOpTimeAvailable = 289; + const TransactionExceededLifetimeLimitSeconds = 290; + const NoQueryExecutionPlans = 291; + const QueryExceededMemoryLimitNoDiskUseAllowed = 292; + const InvalidSeedList = 293; + const InvalidTopologyType = 294; + const InvalidHeartBeatFrequency = 295; + const TopologySetNameRequired = 296; + const HierarchicalAcquisitionLevelViolation = 297; + const InvalidServerType = 298; + const OCSPCertificateStatusRevoked = 299; + const RangeDeletionAbandonedBecauseCollectionWithUUIDDoesNotExist = 300; + const DataCorruptionDetected = 301; + const OCSPCertificateStatusUnknown = 302; + const SplitHorizonChange = 303; + const ShardInvalidatedForTargeting = 304; + const ReadThroughCacheKeyNotFound = 305; + const ReadThroughCacheLookupCanceled = 306; + const RangeDeletionAbandonedBecauseTaskDocumentDoesNotExist = 307; + const CurrentConfigNotCommittedYet = 308; + const SocketException = 9001; + const OBSOLETE_RecvStaleConfig = 9996; + const CannotGrowDocumentInCappedNamespace = 10003; + const NotMaster = 10107; + const BSONObjectTooLarge = 10334; + const DuplicateKey = 11000; + const InterruptedAtShutdown = 11600; + const Interrupted = 11601; + const InterruptedDueToReplStateChange = 11602; + const BackgroundOperationInProgressForDatabase = 12586; + const BackgroundOperationInProgressForNamespace = 12587; + const OBSOLETE_PrepareConfigsFailed = 13104; + const MergeStageNoMatchingDocument = 13113; + const DatabaseDifferCase = 13297; + const StaleConfig = 13388; + const NotMasterNoSlaveOk = 13435; + const NotMasterOrSecondary = 13436; + const OutOfDiskSpace = 14031; + const OSBELETE_KeyTooLong = 17280; + const ClientMarkedKilled = 46841; + + /** + * Checking if instance of error exception is related to mongodb. + * examples: + * try{ + * // mongodb commands ... + * }catch(\Exception $e){ + * if(ErrorCodes::is($e)) + * echo 'this is a mongodb error.'; + * } + * + * try{ + * // mongodb commands ... + * }catch(\Exception $e){ + * if(ErrorCodes::is($e,ErrorCodes::WriteConflict)) + * echo 'this is a mongodb write conflict error.'; + * } + * @param \Exception $e instance of error exception. + * @param int|null $verifyCode if set then returning true value if error code exists. + * @return bool returning true value when this instance is related to mongodb. + * when you set $verifyCode parameter then returns true value if instance is related to mongodb and error code exists. + */ + public static function is($e, $verifyCode = null){ + if( + ($e instanceof YiiMongoDBException && $e->getPrevious() instanceof MongoDBExceptionInterface) + || + $e instanceof MongoDBExceptionInterface + ){ + if($verifyCode !== null && $e->getCode() !== $verifyCode) + return false; + return true; + } + return false; + } +} \ No newline at end of file From 931f82a645d767f23f7213f4c26af2ae65352e92 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:24:16 +0430 Subject: [PATCH 02/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index 513bfa976..1caf264dd 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -15,7 +15,8 @@ * @author Abolfazl Ziaratban */ -class ErrorCodes { +class ErrorCode +{ const OK = 0; const InternalError = 1; @@ -377,4 +378,4 @@ public static function is($e, $verifyCode = null){ } return false; } -} \ No newline at end of file +} From 81d14b9d782cfef901f4c6d665ce86051aa2956d Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:49:13 +0430 Subject: [PATCH 03/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index 1caf264dd..e100c041d 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -366,7 +366,8 @@ class ErrorCode * @return bool returning true value when this instance is related to mongodb. * when you set $verifyCode parameter then returns true value if instance is related to mongodb and error code exists. */ - public static function is($e, $verifyCode = null){ + public static function is($e, $verifyCode = null) + { if( ($e instanceof YiiMongoDBException && $e->getPrevious() instanceof MongoDBExceptionInterface) || From 8cf37ac8165131f8ef9b0fbfdc2a9a89c16fdb6c Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:49:31 +0430 Subject: [PATCH 04/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index e100c041d..12926489a 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -348,7 +348,8 @@ class ErrorCode /** * Checking if instance of error exception is related to mongodb. * examples: - * try{ + * ```php + * try { * // mongodb commands ... * }catch(\Exception $e){ * if(ErrorCodes::is($e)) From 2cbe683532a2ace469e9aebb1af10726f28fba38 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:50:49 +0430 Subject: [PATCH 05/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index 12926489a..7674ea652 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -11,7 +11,8 @@ use yii\mongodb\Exception as YiiMongoDBException; /** - * All errors code in mongodb. generated from https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml + * MongoDB error codes. + * @see https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml * @author Abolfazl Ziaratban */ From 6676f633664f0fa17a9249a31e8301ce825eda3c Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:51:29 +0430 Subject: [PATCH 06/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index 7674ea652..5354c9dc6 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -352,7 +352,7 @@ class ErrorCode * ```php * try { * // mongodb commands ... - * }catch(\Exception $e){ + * } catch(\Exception $e) { * if(ErrorCodes::is($e)) * echo 'this is a mongodb error.'; * } From bd006fb15109a9c013d85cf8552174026617ef02 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:51:38 +0430 Subject: [PATCH 07/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index 5354c9dc6..66205fe56 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -353,7 +353,7 @@ class ErrorCode * try { * // mongodb commands ... * } catch(\Exception $e) { - * if(ErrorCodes::is($e)) + * if (ErrorCode::is($e)) { * echo 'this is a mongodb error.'; * } * From f5001cce4d6c0a494d9ce22f794eb932fd5d1794 Mon Sep 17 00:00:00 2001 From: Abolfazl Date: Thu, 9 Apr 2020 22:51:44 +0430 Subject: [PATCH 08/10] Update src/ErrorCodes.php Co-Authored-By: Alexander Makarov --- src/ErrorCodes.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ErrorCodes.php b/src/ErrorCodes.php index 66205fe56..962d6eb1c 100644 --- a/src/ErrorCodes.php +++ b/src/ErrorCodes.php @@ -355,6 +355,7 @@ class ErrorCode * } catch(\Exception $e) { * if (ErrorCode::is($e)) { * echo 'this is a mongodb error.'; + * } * } * * try{ From c0736edbc8e9e8e8a885bfc2305117c3a76040e0 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Thu, 9 Apr 2020 22:55:00 +0430 Subject: [PATCH 09/10] rename ErrorCodes to ErrorCode --- src/{ErrorCodes.php => ErrorCode.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ErrorCodes.php => ErrorCode.php} (100%) diff --git a/src/ErrorCodes.php b/src/ErrorCode.php similarity index 100% rename from src/ErrorCodes.php rename to src/ErrorCode.php From ec98a5b15b935509529004cd1cd35160292b66df Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Thu, 9 Apr 2020 23:02:54 +0430 Subject: [PATCH 10/10] Update ErrorCode.php --- src/ErrorCode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ErrorCode.php b/src/ErrorCode.php index 962d6eb1c..3737e230c 100644 --- a/src/ErrorCode.php +++ b/src/ErrorCode.php @@ -372,9 +372,9 @@ class ErrorCode public static function is($e, $verifyCode = null) { if( - ($e instanceof YiiMongoDBException && $e->getPrevious() instanceof MongoDBExceptionInterface) - || $e instanceof MongoDBExceptionInterface + || + ($e instanceof YiiMongoDBException && $e->getPrevious() instanceof MongoDBExceptionInterface) ){ if($verifyCode !== null && $e->getCode() !== $verifyCode) return false;