| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.MongoWriteConcernError = exports.MongoServerSelectionError = exports.MongoSystemError = exports.MongoMissingDependencyError = exports.MongoMissingCredentialsError = exports.MongoCompatibilityError = exports.MongoInvalidArgumentError = exports.MongoParseError = exports.MongoNetworkTimeoutError = exports.MongoNetworkError = exports.MongoClientClosedError = exports.MongoTopologyClosedError = exports.MongoCursorExhaustedError = exports.MongoServerClosedError = exports.MongoCursorInUseError = exports.MongoOperationTimeoutError = exports.MongoUnexpectedServerResponseError = exports.MongoGridFSChunkError = exports.MongoGridFSStreamError = exports.MongoTailableCursorError = exports.MongoChangeStreamError = exports.MongoClientBulkWriteExecutionError = exports.MongoClientBulkWriteCursorError = exports.MongoClientBulkWriteError = exports.MongoGCPError = exports.MongoAzureError = exports.MongoOIDCError = exports.MongoAWSError = exports.MongoKerberosError = exports.MongoExpiredSessionError = exports.MongoTransactionError = exports.MongoNotConnectedError = exports.MongoDecompressionError = exports.MongoBatchReExecutionError = exports.MongoStalePrimaryError = 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;
- exports.needsRetryableWriteLabel = needsRetryableWriteLabel;
- exports.isRetryableWriteError = isRetryableWriteError;
- exports.isRetryableReadError = isRetryableReadError;
- exports.isNodeShuttingDownError = isNodeShuttingDownError;
- exports.isSDAMUnrecoverableError = isSDAMUnrecoverableError;
- exports.isNetworkTimeoutError = isNetworkTimeoutError;
- exports.isResumableError = isResumableError;
- /**
- * @internal
- * The legacy error message from the server that indicates the node is not a writable primary
- * https://github.com/mongodb/specifications/blob/921232976f9913cf17415b5ef937ee772e45e6ae/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#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/921232976f9913cf17415b5ef937ee772e45e6ae/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#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/921232976f9913cf17415b5ef937ee772e45e6ae/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#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,
- AuthenticationFailed: 18,
- 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,
- // WriteConcernTimeout is WriteConcernFailed on pre-8.1 servers
- WriteConcernTimeout: 64,
- NamespaceNotFound: 26,
- IllegalOperation: 20,
- MaxTimeMSExpired: 50,
- UnknownReplWriteConcern: 79,
- UnsatisfiableWriteConcern: 100,
- Reauthenticate: 391,
- ReadConcernMajorityNotAvailableYet: 134
- });
- // From spec https://github.com/mongodb/specifications/blob/921232976f9913cf17415b5ef937ee772e45e6ae/source/change-streams/change-streams.md#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',
- PoolRequestedRetry: 'PoolRequestedRetry',
- InterruptInUseConnections: 'InterruptInUseConnections',
- NoWritesPerformed: 'NoWritesPerformed'
- });
- function isAggregateError(e) {
- return e != null && typeof e === 'object' && '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 {
- get errorLabels() {
- return Array.from(this.errorLabelSet);
- }
- /**
- * **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);
- /** @internal */
- this.errorLabelSet = 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 != null && typeof e === 'object' && 'message' in e && typeof e.message === 'string'
- ? e.message
- : 'empty error 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.errorLabelSet.has(label);
- }
- addErrorLabel(label) {
- this.errorLabelSet.add(label);
- }
- }
- 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) {
- for (const label of message.errorLabels)
- this.addErrorLabel(label);
- }
- this.errorResponse = message;
- for (const name in message) {
- if (name !== 'errorLabels' &&
- name !== 'errmsg' &&
- name !== 'message' &&
- name !== 'errorResponse') {
- 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 primary server is marked stale, never directly thrown
- *
- * @public
- * @category Error
- */
- class MongoStalePrimaryError 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, options) {
- super(message, options);
- }
- get name() {
- return 'MongoStalePrimaryError';
- }
- }
- exports.MongoStalePrimaryError = MongoStalePrimaryError;
- /**
- * 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, options) {
- super(message, options);
- }
- get name() {
- return 'MongoAWSError';
- }
- }
- exports.MongoAWSError = MongoAWSError;
- /**
- * A error generated when the user attempts to authenticate
- * via OIDC callbacks, but fails.
- *
- * @public
- * @category Error
- */
- class MongoOIDCError 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 'MongoOIDCError';
- }
- }
- exports.MongoOIDCError = MongoOIDCError;
- /**
- * A error generated when the user attempts to authenticate
- * via Azure, but fails.
- *
- * @public
- * @category Error
- */
- class MongoAzureError extends MongoOIDCError {
- /**
- * **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;
- /**
- * A error generated when the user attempts to authenticate
- * via GCP, but fails.
- *
- * @public
- * @category Error
- */
- class MongoGCPError extends MongoOIDCError {
- /**
- * **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 'MongoGCPError';
- }
- }
- exports.MongoGCPError = MongoGCPError;
- /**
- * An error indicating that an error occurred when executing the bulk write.
- *
- * @public
- * @category Error
- */
- class MongoClientBulkWriteError extends MongoServerError {
- /**
- * Initialize the client bulk write error.
- * @param message - The error message.
- */
- constructor(message) {
- super(message);
- this.writeConcernErrors = [];
- this.writeErrors = new Map();
- }
- get name() {
- return 'MongoClientBulkWriteError';
- }
- }
- exports.MongoClientBulkWriteError = MongoClientBulkWriteError;
- /**
- * An error indicating that an error occurred when processing bulk write results.
- *
- * @public
- * @category Error
- */
- class MongoClientBulkWriteCursorError 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 'MongoClientBulkWriteCursorError';
- }
- }
- exports.MongoClientBulkWriteCursorError = MongoClientBulkWriteCursorError;
- /**
- * An error indicating that an error occurred on the client when executing a client bulk write.
- *
- * @public
- * @category Error
- */
- class MongoClientBulkWriteExecutionError 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 'MongoClientBulkWriteExecutionError';
- }
- }
- exports.MongoClientBulkWriteExecutionError = MongoClientBulkWriteExecutionError;
- /**
- * 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, options) {
- super(message, options);
- }
- get name() {
- return 'MongoUnexpectedServerResponseError';
- }
- }
- exports.MongoUnexpectedServerResponseError = MongoUnexpectedServerResponseError;
- /**
- * @public
- * @category Error
- *
- * The `MongoOperationTimeoutError` class represents an error that occurs when an operation could not be completed within the specified `timeoutMS`.
- * It is generated by the driver in support of the "client side operation timeout" feature so inherits from `MongoDriverError`.
- * When `timeoutMS` is enabled `MongoServerError`s relating to `MaxTimeExpired` errors will be converted to `MongoOperationTimeoutError`
- *
- * @example
- * ```ts
- * try {
- * await blogs.insertOne(blogPost, { timeoutMS: 60_000 })
- * } catch (error) {
- * if (error instanceof MongoOperationTimeoutError) {
- * console.log(`Oh no! writer's block!`, error);
- * }
- * }
- * ```
- */
- class MongoOperationTimeoutError extends MongoDriverError {
- get name() {
- return 'MongoOperationTimeoutError';
- }
- }
- exports.MongoOperationTimeoutError = MongoOperationTimeoutError;
- /**
- * 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;
- /**
- * An error generated when the MongoClient is closed and async
- * operations are interrupted.
- *
- * @public
- * @category Error
- */
- class MongoClientClosedError 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() {
- super('Operation interrupted because client was closed');
- }
- get name() {
- return 'MongoClientClosedError';
- }
- }
- exports.MongoClientClosedError = MongoClientClosedError;
- /**
- * 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 });
- this.beforeHandshake = !!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, options) {
- super(message, options);
- }
- 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);
- this.dependencyName = options.dependencyName;
- }
- 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;
- /**
- * 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(result) {
- super({ ...result.writeConcernError, ...result });
- this.errInfo = result.writeConcernError.errInfo;
- this.result = result;
- }
- get name() {
- return 'MongoWriteConcernError';
- }
- }
- exports.MongoWriteConcernError = MongoWriteConcernError;
- // https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.md#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,
- exports.MONGODB_ERROR_CODES.ExceededTimeLimit,
- exports.MONGODB_ERROR_CODES.ReadConcernMajorityNotAvailableYet
- ]);
- // see: https://github.com/mongodb/specifications/blob/master/source/retryable-writes/retryable-writes.md#terms
- const RETRYABLE_WRITE_ERROR_CODES = RETRYABLE_READ_ERROR_CODES;
- function needsRetryableWriteLabel(error, maxWireVersion, serverType) {
- // 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 || isRetryableWriteError(error)) &&
- !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) {
- if (serverType === 'Mongos' && maxWireVersion < 9) {
- // use original top-level code from server response
- return RETRYABLE_WRITE_ERROR_CODES.has(error.result.code ?? 0);
- }
- const code = error.result.writeConcernError.code ?? Number(error.code);
- return RETRYABLE_WRITE_ERROR_CODES.has(Number.isNaN(code) ? 0 : code);
- }
- if (error instanceof MongoError) {
- return RETRYABLE_WRITE_ERROR_CODES.has(Number(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;
- }
- function isRetryableWriteError(error) {
- return (error.hasErrorLabel(exports.MongoErrorLabel.RetryableWriteError) ||
- error.hasErrorLabel(exports.MongoErrorLabel.PoolRequestedRetry));
- }
- /** 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;
- }
- 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));
- }
- /**
- * 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.md#not-writable-primary-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);
- }
- function isNetworkTimeoutError(err) {
- return !!(err instanceof MongoNetworkError && err.message.match(/timed out/));
- }
- function isResumableError(error, wireVersion) {
- if (error == null || !(error instanceof MongoError)) {
- return false;
- }
- if (error instanceof MongoNetworkError) {
- return true;
- }
- if (error instanceof MongoServerSelectionError) {
- 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;
- }
- //# sourceMappingURL=error.js.map
|