12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.isResumableError = exports.isNetworkTimeoutError = exports.isSDAMUnrecoverableError = exports.isNodeShuttingDownError = exports.isRetryableReadError = exports.isRetryableWriteError = exports.needsRetryableWriteLabel = exports.MongoWriteConcernError = exports.MongoServerSelectionError = exports.MongoSystemError = exports.MongoMissingDependencyError = exports.MongoMissingCredentialsError = exports.MongoCompatibilityError = exports.MongoInvalidArgumentError = exports.MongoParseError = exports.MongoNetworkTimeoutError = exports.MongoNetworkError = exports.isNetworkErrorBeforeHandshake = exports.MongoTopologyClosedError = exports.MongoCursorExhaustedError = exports.MongoServerClosedError = exports.MongoCursorInUseError = exports.MongoUnexpectedServerResponseError = exports.MongoGridFSChunkError = exports.MongoGridFSStreamError = exports.MongoTailableCursorError = exports.MongoChangeStreamError = exports.MongoAzureError = exports.MongoAWSError = exports.MongoKerberosError = exports.MongoExpiredSessionError = exports.MongoTransactionError = exports.MongoNotConnectedError = exports.MongoDecompressionError = exports.MongoBatchReExecutionError = exports.MongoRuntimeError = exports.MongoAPIError = exports.MongoDriverError = exports.MongoServerError = exports.MongoError = exports.MongoErrorLabel = exports.GET_MORE_RESUMABLE_CODES = exports.MONGODB_ERROR_CODES = exports.NODE_IS_RECOVERING_ERROR_MESSAGE = exports.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = void 0;
- /** @internal */
- const kErrorLabels = Symbol('errorLabels');
- /**
- * @internal
- * The legacy error message from the server that indicates the node is not a writable primary
- * https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
- */
- exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = new RegExp('not master', 'i');
- /**
- * @internal
- * The legacy error message from the server that indicates the node is not a primary or secondary
- * https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
- */
- exports.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = new RegExp('not master or secondary', 'i');
- /**
- * @internal
- * The error message from the server that indicates the node is recovering
- * https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
- */
- exports.NODE_IS_RECOVERING_ERROR_MESSAGE = new RegExp('node is recovering', 'i');
- /** @internal MongoDB Error Codes */
- exports.MONGODB_ERROR_CODES = Object.freeze({
- HostUnreachable: 6,
- HostNotFound: 7,
- NetworkTimeout: 89,
- ShutdownInProgress: 91,
- PrimarySteppedDown: 189,
- ExceededTimeLimit: 262,
- SocketException: 9001,
- NotWritablePrimary: 10107,
- InterruptedAtShutdown: 11600,
- InterruptedDueToReplStateChange: 11602,
- NotPrimaryNoSecondaryOk: 13435,
- NotPrimaryOrSecondary: 13436,
- StaleShardVersion: 63,
- StaleEpoch: 150,
- StaleConfig: 13388,
- RetryChangeStream: 234,
- FailedToSatisfyReadPreference: 133,
- CursorNotFound: 43,
- LegacyNotPrimary: 10058,
- WriteConcernFailed: 64,
- NamespaceNotFound: 26,
- IllegalOperation: 20,
- MaxTimeMSExpired: 50,
- UnknownReplWriteConcern: 79,
- UnsatisfiableWriteConcern: 100,
- Reauthenticate: 391
- });
- // From spec@https://github.com/mongodb/specifications/blob/f93d78191f3db2898a59013a7ed5650352ef6da8/source/change-streams/change-streams.rst#resumable-error
- exports.GET_MORE_RESUMABLE_CODES = new Set([
- exports.MONGODB_ERROR_CODES.HostUnreachable,
- exports.MONGODB_ERROR_CODES.HostNotFound,
- exports.MONGODB_ERROR_CODES.NetworkTimeout,
- exports.MONGODB_ERROR_CODES.ShutdownInProgress,
- exports.MONGODB_ERROR_CODES.PrimarySteppedDown,
- exports.MONGODB_ERROR_CODES.ExceededTimeLimit,
- exports.MONGODB_ERROR_CODES.SocketException,
- exports.MONGODB_ERROR_CODES.NotWritablePrimary,
- exports.MONGODB_ERROR_CODES.InterruptedAtShutdown,
- exports.MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
- exports.MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
- exports.MONGODB_ERROR_CODES.NotPrimaryOrSecondary,
- exports.MONGODB_ERROR_CODES.StaleShardVersion,
- exports.MONGODB_ERROR_CODES.StaleEpoch,
- exports.MONGODB_ERROR_CODES.StaleConfig,
- exports.MONGODB_ERROR_CODES.RetryChangeStream,
- exports.MONGODB_ERROR_CODES.FailedToSatisfyReadPreference,
- exports.MONGODB_ERROR_CODES.CursorNotFound
- ]);
- /** @public */
- exports.MongoErrorLabel = Object.freeze({
- RetryableWriteError: 'RetryableWriteError',
- TransientTransactionError: 'TransientTransactionError',
- UnknownTransactionCommitResult: 'UnknownTransactionCommitResult',
- ResumableChangeStreamError: 'ResumableChangeStreamError',
- HandshakeError: 'HandshakeError',
- ResetPool: 'ResetPool',
- InterruptInUseConnections: 'InterruptInUseConnections',
- NoWritesPerformed: 'NoWritesPerformed'
- });
- function isAggregateError(e) {
- return 'errors' in e && Array.isArray(e.errors);
- }
- /**
- * @public
- * @category Error
- *
- * @privateRemarks
- * mongodb-client-encryption has a dependency on this error, it uses the constructor with a string argument
- */
- class MongoError extends Error {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options) {
- super(message, options);
- this[kErrorLabels] = new Set();
- }
- /** @internal */
- static buildErrorMessage(e) {
- if (typeof e === 'string') {
- return e;
- }
- if (isAggregateError(e) && e.message.length === 0) {
- return e.errors.length === 0
- ? 'AggregateError has an empty errors array. Please check the `cause` property for more information.'
- : e.errors.map(({ message }) => message).join(', ');
- }
- return e.message;
- }
- get name() {
- return 'MongoError';
- }
- /** Legacy name for server error responses */
- get errmsg() {
- return this.message;
- }
- /**
- * Checks the error to see if it has an error label
- *
- * @param label - The error label to check for
- * @returns returns true if the error has the provided error label
- */
- hasErrorLabel(label) {
- return this[kErrorLabels].has(label);
- }
- addErrorLabel(label) {
- this[kErrorLabels].add(label);
- }
- get errorLabels() {
- return Array.from(this[kErrorLabels]);
- }
- }
- exports.MongoError = MongoError;
- /**
- * An error coming from the mongo server
- *
- * @public
- * @category Error
- */
- class MongoServerError extends MongoError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message.message || message.errmsg || message.$err || 'n/a');
- if (message.errorLabels) {
- this[kErrorLabels] = new Set(message.errorLabels);
- }
- for (const name in message) {
- if (name !== 'errorLabels' && name !== 'errmsg' && name !== 'message')
- this[name] = message[name];
- }
- }
- get name() {
- return 'MongoServerError';
- }
- }
- exports.MongoServerError = MongoServerError;
- /**
- * An error generated by the driver
- *
- * @public
- * @category Error
- */
- class MongoDriverError extends MongoError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options) {
- super(message, options);
- }
- get name() {
- return 'MongoDriverError';
- }
- }
- exports.MongoDriverError = MongoDriverError;
- /**
- * An error generated when the driver API is used incorrectly
- *
- * @privateRemarks
- * Should **never** be directly instantiated
- *
- * @public
- * @category Error
- */
- class MongoAPIError extends MongoDriverError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options) {
- super(message, options);
- }
- get name() {
- return 'MongoAPIError';
- }
- }
- exports.MongoAPIError = MongoAPIError;
- /**
- * An error generated when the driver encounters unexpected input
- * or reaches an unexpected/invalid internal state
- *
- * @privateRemarks
- * Should **never** be directly instantiated.
- *
- * @public
- * @category Error
- */
- class MongoRuntimeError extends MongoDriverError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options) {
- super(message, options);
- }
- get name() {
- return 'MongoRuntimeError';
- }
- }
- exports.MongoRuntimeError = MongoRuntimeError;
- /**
- * An error generated when a batch command is re-executed after one of the commands in the batch
- * has failed
- *
- * @public
- * @category Error
- */
- class MongoBatchReExecutionError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message = 'This batch has already been executed, create new batch to execute') {
- super(message);
- }
- get name() {
- return 'MongoBatchReExecutionError';
- }
- }
- exports.MongoBatchReExecutionError = MongoBatchReExecutionError;
- /**
- * An error generated when the driver fails to decompress
- * data received from the server.
- *
- * @public
- * @category Error
- */
- class MongoDecompressionError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoDecompressionError';
- }
- }
- exports.MongoDecompressionError = MongoDecompressionError;
- /**
- * An error thrown when the user attempts to operate on a database or collection through a MongoClient
- * that has not yet successfully called the "connect" method
- *
- * @public
- * @category Error
- */
- class MongoNotConnectedError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoNotConnectedError';
- }
- }
- exports.MongoNotConnectedError = MongoNotConnectedError;
- /**
- * An error generated when the user makes a mistake in the usage of transactions.
- * (e.g. attempting to commit a transaction with a readPreference other than primary)
- *
- * @public
- * @category Error
- */
- class MongoTransactionError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoTransactionError';
- }
- }
- exports.MongoTransactionError = MongoTransactionError;
- /**
- * An error generated when the user attempts to operate
- * on a session that has expired or has been closed.
- *
- * @public
- * @category Error
- */
- class MongoExpiredSessionError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message = 'Cannot use a session that has ended') {
- super(message);
- }
- get name() {
- return 'MongoExpiredSessionError';
- }
- }
- exports.MongoExpiredSessionError = MongoExpiredSessionError;
- /**
- * A error generated when the user attempts to authenticate
- * via Kerberos, but fails to connect to the Kerberos client.
- *
- * @public
- * @category Error
- */
- class MongoKerberosError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoKerberosError';
- }
- }
- exports.MongoKerberosError = MongoKerberosError;
- /**
- * A error generated when the user attempts to authenticate
- * via AWS, but fails
- *
- * @public
- * @category Error
- */
- class MongoAWSError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoAWSError';
- }
- }
- exports.MongoAWSError = MongoAWSError;
- /**
- * A error generated when the user attempts to authenticate
- * via Azure, but fails.
- *
- * @public
- * @category Error
- */
- class MongoAzureError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoAzureError';
- }
- }
- exports.MongoAzureError = MongoAzureError;
- /**
- * An error generated when a ChangeStream operation fails to execute.
- *
- * @public
- * @category Error
- */
- class MongoChangeStreamError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoChangeStreamError';
- }
- }
- exports.MongoChangeStreamError = MongoChangeStreamError;
- /**
- * An error thrown when the user calls a function or method not supported on a tailable cursor
- *
- * @public
- * @category Error
- */
- class MongoTailableCursorError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message = 'Tailable cursor does not support this operation') {
- super(message);
- }
- get name() {
- return 'MongoTailableCursorError';
- }
- }
- exports.MongoTailableCursorError = MongoTailableCursorError;
- /** An error generated when a GridFSStream operation fails to execute.
- *
- * @public
- * @category Error
- */
- class MongoGridFSStreamError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoGridFSStreamError';
- }
- }
- exports.MongoGridFSStreamError = MongoGridFSStreamError;
- /**
- * An error generated when a malformed or invalid chunk is
- * encountered when reading from a GridFSStream.
- *
- * @public
- * @category Error
- */
- class MongoGridFSChunkError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoGridFSChunkError';
- }
- }
- exports.MongoGridFSChunkError = MongoGridFSChunkError;
- /**
- * An error generated when a **parsable** unexpected response comes from the server.
- * This is generally an error where the driver in a state expecting a certain behavior to occur in
- * the next message from MongoDB but it receives something else.
- * This error **does not** represent an issue with wire message formatting.
- *
- * #### Example
- * When an operation fails, it is the driver's job to retry it. It must perform serverSelection
- * again to make sure that it attempts the operation against a server in a good state. If server
- * selection returns a server that does not support retryable operations, this error is used.
- * This scenario is unlikely as retryable support would also have been determined on the first attempt
- * but it is possible the state change could report a selectable server that does not support retries.
- *
- * @public
- * @category Error
- */
- class MongoUnexpectedServerResponseError extends MongoRuntimeError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoUnexpectedServerResponseError';
- }
- }
- exports.MongoUnexpectedServerResponseError = MongoUnexpectedServerResponseError;
- /**
- * An error thrown when the user attempts to add options to a cursor that has already been
- * initialized
- *
- * @public
- * @category Error
- */
- class MongoCursorInUseError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message = 'Cursor is already initialized') {
- super(message);
- }
- get name() {
- return 'MongoCursorInUseError';
- }
- }
- exports.MongoCursorInUseError = MongoCursorInUseError;
- /**
- * An error generated when an attempt is made to operate
- * on a closed/closing server.
- *
- * @public
- * @category Error
- */
- class MongoServerClosedError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message = 'Server is closed') {
- super(message);
- }
- get name() {
- return 'MongoServerClosedError';
- }
- }
- exports.MongoServerClosedError = MongoServerClosedError;
- /**
- * An error thrown when an attempt is made to read from a cursor that has been exhausted
- *
- * @public
- * @category Error
- */
- class MongoCursorExhaustedError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message || 'Cursor is exhausted');
- }
- get name() {
- return 'MongoCursorExhaustedError';
- }
- }
- exports.MongoCursorExhaustedError = MongoCursorExhaustedError;
- /**
- * An error generated when an attempt is made to operate on a
- * dropped, or otherwise unavailable, database.
- *
- * @public
- * @category Error
- */
- class MongoTopologyClosedError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message = 'Topology is closed') {
- super(message);
- }
- get name() {
- return 'MongoTopologyClosedError';
- }
- }
- exports.MongoTopologyClosedError = MongoTopologyClosedError;
- /** @internal */
- const kBeforeHandshake = Symbol('beforeHandshake');
- function isNetworkErrorBeforeHandshake(err) {
- return err[kBeforeHandshake] === true;
- }
- exports.isNetworkErrorBeforeHandshake = isNetworkErrorBeforeHandshake;
- /**
- * An error indicating an issue with the network, including TCP errors and timeouts.
- * @public
- * @category Error
- */
- class MongoNetworkError extends MongoError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options) {
- super(message, { cause: options?.cause });
- if (options && typeof options.beforeHandshake === 'boolean') {
- this[kBeforeHandshake] = options.beforeHandshake;
- }
- }
- get name() {
- return 'MongoNetworkError';
- }
- }
- exports.MongoNetworkError = MongoNetworkError;
- /**
- * An error indicating a network timeout occurred
- * @public
- * @category Error
- *
- * @privateRemarks
- * mongodb-client-encryption has a dependency on this error with an instanceof check
- */
- class MongoNetworkTimeoutError extends MongoNetworkError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options) {
- super(message, options);
- }
- get name() {
- return 'MongoNetworkTimeoutError';
- }
- }
- exports.MongoNetworkTimeoutError = MongoNetworkTimeoutError;
- /**
- * An error used when attempting to parse a value (like a connection string)
- * @public
- * @category Error
- */
- class MongoParseError extends MongoDriverError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoParseError';
- }
- }
- exports.MongoParseError = MongoParseError;
- /**
- * An error generated when the user supplies malformed or unexpected arguments
- * or when a required argument or field is not provided.
- *
- *
- * @public
- * @category Error
- */
- class MongoInvalidArgumentError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoInvalidArgumentError';
- }
- }
- exports.MongoInvalidArgumentError = MongoInvalidArgumentError;
- /**
- * An error generated when a feature that is not enabled or allowed for the current server
- * configuration is used
- *
- *
- * @public
- * @category Error
- */
- class MongoCompatibilityError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoCompatibilityError';
- }
- }
- exports.MongoCompatibilityError = MongoCompatibilityError;
- /**
- * An error generated when the user fails to provide authentication credentials before attempting
- * to connect to a mongo server instance.
- *
- *
- * @public
- * @category Error
- */
- class MongoMissingCredentialsError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message) {
- super(message);
- }
- get name() {
- return 'MongoMissingCredentialsError';
- }
- }
- exports.MongoMissingCredentialsError = MongoMissingCredentialsError;
- /**
- * An error generated when a required module or dependency is not present in the local environment
- *
- * @public
- * @category Error
- */
- class MongoMissingDependencyError extends MongoAPIError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, options = {}) {
- super(message, options);
- }
- get name() {
- return 'MongoMissingDependencyError';
- }
- }
- exports.MongoMissingDependencyError = MongoMissingDependencyError;
- /**
- * An error signifying a general system issue
- * @public
- * @category Error
- */
- class MongoSystemError extends MongoError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, reason) {
- if (reason && reason.error) {
- super(MongoError.buildErrorMessage(reason.error.message || reason.error), {
- cause: reason.error
- });
- }
- else {
- super(message);
- }
- if (reason) {
- this.reason = reason;
- }
- this.code = reason.error?.code;
- }
- get name() {
- return 'MongoSystemError';
- }
- }
- exports.MongoSystemError = MongoSystemError;
- /**
- * An error signifying a client-side server selection error
- * @public
- * @category Error
- */
- class MongoServerSelectionError extends MongoSystemError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, reason) {
- super(message, reason);
- }
- get name() {
- return 'MongoServerSelectionError';
- }
- }
- exports.MongoServerSelectionError = MongoServerSelectionError;
- function makeWriteConcernResultObject(input) {
- const output = Object.assign({}, input);
- if (output.ok === 0) {
- output.ok = 1;
- delete output.errmsg;
- delete output.code;
- delete output.codeName;
- }
- return output;
- }
- /**
- * An error thrown when the server reports a writeConcernError
- * @public
- * @category Error
- */
- class MongoWriteConcernError extends MongoServerError {
- /**
- * **Do not use this constructor!**
- *
- * Meant for internal use only.
- *
- * @remarks
- * This class is only meant to be constructed within the driver. This constructor is
- * not subject to semantic versioning compatibility guarantees and may change at any time.
- *
- * @public
- **/
- constructor(message, result) {
- if (result && Array.isArray(result.errorLabels)) {
- message.errorLabels = result.errorLabels;
- }
- super(message);
- this.errInfo = message.errInfo;
- if (result != null) {
- this.result = makeWriteConcernResultObject(result);
- }
- }
- get name() {
- return 'MongoWriteConcernError';
- }
- }
- exports.MongoWriteConcernError = MongoWriteConcernError;
- // https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#retryable-error
- const RETRYABLE_READ_ERROR_CODES = new Set([
- exports.MONGODB_ERROR_CODES.HostUnreachable,
- exports.MONGODB_ERROR_CODES.HostNotFound,
- exports.MONGODB_ERROR_CODES.NetworkTimeout,
- exports.MONGODB_ERROR_CODES.ShutdownInProgress,
- exports.MONGODB_ERROR_CODES.PrimarySteppedDown,
- exports.MONGODB_ERROR_CODES.SocketException,
- exports.MONGODB_ERROR_CODES.NotWritablePrimary,
- exports.MONGODB_ERROR_CODES.InterruptedAtShutdown,
- exports.MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
- exports.MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
- exports.MONGODB_ERROR_CODES.NotPrimaryOrSecondary
- ]);
- // see: https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.rst#terms
- const RETRYABLE_WRITE_ERROR_CODES = new Set([
- ...RETRYABLE_READ_ERROR_CODES,
- exports.MONGODB_ERROR_CODES.ExceededTimeLimit
- ]);
- function needsRetryableWriteLabel(error, maxWireVersion) {
- // pre-4.4 server, then the driver adds an error label for every valid case
- // execute operation will only inspect the label, code/message logic is handled here
- if (error instanceof MongoNetworkError) {
- return true;
- }
- if (error instanceof MongoError) {
- if ((maxWireVersion >= 9 || error.hasErrorLabel(exports.MongoErrorLabel.RetryableWriteError)) &&
- !error.hasErrorLabel(exports.MongoErrorLabel.HandshakeError)) {
- // If we already have the error label no need to add it again. 4.4+ servers add the label.
- // In the case where we have a handshake error, need to fall down to the logic checking
- // the codes.
- return false;
- }
- }
- if (error instanceof MongoWriteConcernError) {
- return RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
- }
- if (error instanceof MongoError && typeof error.code === 'number') {
- return RETRYABLE_WRITE_ERROR_CODES.has(error.code);
- }
- const isNotWritablePrimaryError = exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(error.message);
- if (isNotWritablePrimaryError) {
- return true;
- }
- const isNodeIsRecoveringError = exports.NODE_IS_RECOVERING_ERROR_MESSAGE.test(error.message);
- if (isNodeIsRecoveringError) {
- return true;
- }
- return false;
- }
- exports.needsRetryableWriteLabel = needsRetryableWriteLabel;
- function isRetryableWriteError(error) {
- return error.hasErrorLabel(exports.MongoErrorLabel.RetryableWriteError);
- }
- exports.isRetryableWriteError = isRetryableWriteError;
- /** Determines whether an error is something the driver should attempt to retry */
- function isRetryableReadError(error) {
- const hasRetryableErrorCode = typeof error.code === 'number' ? RETRYABLE_READ_ERROR_CODES.has(error.code) : false;
- if (hasRetryableErrorCode) {
- return true;
- }
- if (error instanceof MongoNetworkError) {
- return true;
- }
- const isNotWritablePrimaryError = exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(error.message);
- if (isNotWritablePrimaryError) {
- return true;
- }
- const isNodeIsRecoveringError = exports.NODE_IS_RECOVERING_ERROR_MESSAGE.test(error.message);
- if (isNodeIsRecoveringError) {
- return true;
- }
- return false;
- }
- exports.isRetryableReadError = isRetryableReadError;
- const SDAM_RECOVERING_CODES = new Set([
- exports.MONGODB_ERROR_CODES.ShutdownInProgress,
- exports.MONGODB_ERROR_CODES.PrimarySteppedDown,
- exports.MONGODB_ERROR_CODES.InterruptedAtShutdown,
- exports.MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
- exports.MONGODB_ERROR_CODES.NotPrimaryOrSecondary
- ]);
- const SDAM_NOT_PRIMARY_CODES = new Set([
- exports.MONGODB_ERROR_CODES.NotWritablePrimary,
- exports.MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
- exports.MONGODB_ERROR_CODES.LegacyNotPrimary
- ]);
- const SDAM_NODE_SHUTTING_DOWN_ERROR_CODES = new Set([
- exports.MONGODB_ERROR_CODES.InterruptedAtShutdown,
- exports.MONGODB_ERROR_CODES.ShutdownInProgress
- ]);
- function isRecoveringError(err) {
- if (typeof err.code === 'number') {
- // If any error code exists, we ignore the error.message
- return SDAM_RECOVERING_CODES.has(err.code);
- }
- return (exports.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE.test(err.message) ||
- exports.NODE_IS_RECOVERING_ERROR_MESSAGE.test(err.message));
- }
- function isNotWritablePrimaryError(err) {
- if (typeof err.code === 'number') {
- // If any error code exists, we ignore the error.message
- return SDAM_NOT_PRIMARY_CODES.has(err.code);
- }
- if (isRecoveringError(err)) {
- return false;
- }
- return exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(err.message);
- }
- function isNodeShuttingDownError(err) {
- return !!(typeof err.code === 'number' && SDAM_NODE_SHUTTING_DOWN_ERROR_CODES.has(err.code));
- }
- exports.isNodeShuttingDownError = isNodeShuttingDownError;
- /**
- * Determines whether SDAM can recover from a given error. If it cannot
- * then the pool will be cleared, and server state will completely reset
- * locally.
- *
- * @see https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-master-and-node-is-recovering
- */
- function isSDAMUnrecoverableError(error) {
- // NOTE: null check is here for a strictly pre-CMAP world, a timeout or
- // close event are considered unrecoverable
- if (error instanceof MongoParseError || error == null) {
- return true;
- }
- return isRecoveringError(error) || isNotWritablePrimaryError(error);
- }
- exports.isSDAMUnrecoverableError = isSDAMUnrecoverableError;
- function isNetworkTimeoutError(err) {
- return !!(err instanceof MongoNetworkError && err.message.match(/timed out/));
- }
- exports.isNetworkTimeoutError = isNetworkTimeoutError;
- function isResumableError(error, wireVersion) {
- if (error == null || !(error instanceof MongoError)) {
- return false;
- }
- if (error instanceof MongoNetworkError) {
- return true;
- }
- if (wireVersion != null && wireVersion >= 9) {
- // DRIVERS-1308: For 4.4 drivers running against 4.4 servers, drivers will add a special case to treat the CursorNotFound error code as resumable
- if (error.code === exports.MONGODB_ERROR_CODES.CursorNotFound) {
- return true;
- }
- return error.hasErrorLabel(exports.MongoErrorLabel.ResumableChangeStreamError);
- }
- if (typeof error.code === 'number') {
- return exports.GET_MORE_RESUMABLE_CODES.has(error.code);
- }
- return false;
- }
- exports.isResumableError = isResumableError;
- //# sourceMappingURL=error.js.map
|