import type { Document } from './bson'; import type { TopologyVersion } from './sdam/server_description'; import type { TopologyDescription } from './sdam/topology_description'; /** @public */ export declare type AnyError = MongoError | Error; /** @internal */ declare const kErrorLabels: unique symbol; /** * @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 */ export declare const LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE: RegExp; /** * @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 */ export declare const LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE: RegExp; /** * @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 */ export declare const NODE_IS_RECOVERING_ERROR_MESSAGE: RegExp; /** @internal MongoDB Error Codes */ export declare const MONGODB_ERROR_CODES: Readonly<{ readonly HostUnreachable: 6; readonly HostNotFound: 7; readonly NetworkTimeout: 89; readonly ShutdownInProgress: 91; readonly PrimarySteppedDown: 189; readonly ExceededTimeLimit: 262; readonly SocketException: 9001; readonly NotWritablePrimary: 10107; readonly InterruptedAtShutdown: 11600; readonly InterruptedDueToReplStateChange: 11602; readonly NotPrimaryNoSecondaryOk: 13435; readonly NotPrimaryOrSecondary: 13436; readonly StaleShardVersion: 63; readonly StaleEpoch: 150; readonly StaleConfig: 13388; readonly RetryChangeStream: 234; readonly FailedToSatisfyReadPreference: 133; readonly CursorNotFound: 43; readonly LegacyNotPrimary: 10058; readonly WriteConcernFailed: 64; readonly NamespaceNotFound: 26; readonly IllegalOperation: 20; readonly MaxTimeMSExpired: 50; readonly UnknownReplWriteConcern: 79; readonly UnsatisfiableWriteConcern: 100; }>; export declare const GET_MORE_RESUMABLE_CODES: Set; /** @public */ export declare const MongoErrorLabel: Readonly<{ readonly RetryableWriteError: "RetryableWriteError"; readonly TransientTransactionError: "TransientTransactionError"; readonly UnknownTransactionCommitResult: "UnknownTransactionCommitResult"; readonly ResumableChangeStreamError: "ResumableChangeStreamError"; readonly HandshakeError: "HandshakeError"; }>; /** @public */ export declare type MongoErrorLabel = typeof MongoErrorLabel[keyof typeof MongoErrorLabel]; /** @public */ export interface ErrorDescription extends Document { message?: string; errmsg?: string; $err?: string; errorLabels?: string[]; errInfo?: Document; } /** * @public * @category Error * * @privateRemarks * CSFLE has a dependency on this error, it uses the constructor with a string argument */ export declare class MongoError extends Error { /** @internal */ [kErrorLabels]: Set; /** * This is a number in MongoServerError and a string in MongoDriverError * @privateRemarks * Define the type override on the subclasses when we can use the override keyword */ code?: number | string; topologyVersion?: TopologyVersion; constructor(message: string | Error); get name(): string; /** Legacy name for server error responses */ get errmsg(): string; /** * 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: string): boolean; addErrorLabel(label: string): void; get errorLabels(): string[]; } /** * An error coming from the mongo server * * @public * @category Error */ export declare class MongoServerError extends MongoError { codeName?: string; writeConcernError?: Document; errInfo?: Document; ok?: number; [key: string]: any; constructor(message: ErrorDescription); get name(): string; } /** * An error generated by the driver * * @public * @category Error */ export declare class MongoDriverError extends MongoError { constructor(message: string); get name(): string; } /** * An error generated when the driver API is used incorrectly * * @privateRemarks * Should **never** be directly instantiated * * @public * @category Error */ export declare class MongoAPIError extends MongoDriverError { constructor(message: string); get name(): string; } /** * 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 */ export declare class MongoRuntimeError extends MongoDriverError { constructor(message: string); get name(): string; } /** * An error generated when a batch command is re-executed after one of the commands in the batch * has failed * * @public * @category Error */ export declare class MongoBatchReExecutionError extends MongoAPIError { constructor(message?: string); get name(): string; } /** * An error generated when the driver fails to decompress * data received from the server. * * @public * @category Error */ export declare class MongoDecompressionError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * 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 */ export declare class MongoNotConnectedError extends MongoAPIError { constructor(message: string); get name(): string; } /** * 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 */ export declare class MongoTransactionError extends MongoAPIError { constructor(message: string); get name(): string; } /** * An error generated when the user attempts to operate * on a session that has expired or has been closed. * * @public * @category Error */ export declare class MongoExpiredSessionError extends MongoAPIError { constructor(message?: string); get name(): string; } /** * A error generated when the user attempts to authenticate * via Kerberos, but fails to connect to the Kerberos client. * * @public * @category Error */ export declare class MongoKerberosError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * A error generated when the user attempts to authenticate * via AWS, but fails * * @public * @category Error */ export declare class MongoAWSError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * An error generated when a ChangeStream operation fails to execute. * * @public * @category Error */ export declare class MongoChangeStreamError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * An error thrown when the user calls a function or method not supported on a tailable cursor * * @public * @category Error */ export declare class MongoTailableCursorError extends MongoAPIError { constructor(message?: string); get name(): string; } /** An error generated when a GridFSStream operation fails to execute. * * @public * @category Error */ export declare class MongoGridFSStreamError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * An error generated when a malformed or invalid chunk is * encountered when reading from a GridFSStream. * * @public * @category Error */ export declare class MongoGridFSChunkError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * 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 */ export declare class MongoUnexpectedServerResponseError extends MongoRuntimeError { constructor(message: string); get name(): string; } /** * An error thrown when the user attempts to add options to a cursor that has already been * initialized * * @public * @category Error */ export declare class MongoCursorInUseError extends MongoAPIError { constructor(message?: string); get name(): string; } /** * An error generated when an attempt is made to operate * on a closed/closing server. * * @public * @category Error */ export declare class MongoServerClosedError extends MongoAPIError { constructor(message?: string); get name(): string; } /** * An error thrown when an attempt is made to read from a cursor that has been exhausted * * @public * @category Error */ export declare class MongoCursorExhaustedError extends MongoAPIError { constructor(message?: string); get name(): string; } /** * An error generated when an attempt is made to operate on a * dropped, or otherwise unavailable, database. * * @public * @category Error */ export declare class MongoTopologyClosedError extends MongoAPIError { constructor(message?: string); get name(): string; } /** @internal */ declare const kBeforeHandshake: unique symbol; export declare function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean; /** @public */ export interface MongoNetworkErrorOptions { /** Indicates the timeout happened before a connection handshake completed */ beforeHandshake: boolean; } /** * An error indicating an issue with the network, including TCP errors and timeouts. * @public * @category Error */ export declare class MongoNetworkError extends MongoError { /** @internal */ [kBeforeHandshake]?: boolean; constructor(message: string | Error, options?: MongoNetworkErrorOptions); get name(): string; } /** * An error indicating a network timeout occurred * @public * @category Error * * @privateRemarks * CSFLE has a dependency on this error with an instanceof check */ export declare class MongoNetworkTimeoutError extends MongoNetworkError { constructor(message: string, options?: MongoNetworkErrorOptions); get name(): string; } /** * An error used when attempting to parse a value (like a connection string) * @public * @category Error */ export declare class MongoParseError extends MongoDriverError { constructor(message: string); get name(): string; } /** * An error generated when the user supplies malformed or unexpected arguments * or when a required argument or field is not provided. * * * @public * @category Error */ export declare class MongoInvalidArgumentError extends MongoAPIError { constructor(message: string); get name(): string; } /** * An error generated when a feature that is not enabled or allowed for the current server * configuration is used * * * @public * @category Error */ export declare class MongoCompatibilityError extends MongoAPIError { constructor(message: string); get name(): string; } /** * An error generated when the user fails to provide authentication credentials before attempting * to connect to a mongo server instance. * * * @public * @category Error */ export declare class MongoMissingCredentialsError extends MongoAPIError { constructor(message: string); get name(): string; } /** * An error generated when a required module or dependency is not present in the local environment * * @public * @category Error */ export declare class MongoMissingDependencyError extends MongoAPIError { constructor(message: string); get name(): string; } /** * An error signifying a general system issue * @public * @category Error */ export declare class MongoSystemError extends MongoError { /** An optional reason context, such as an error saved during flow of monitoring and selecting servers */ reason?: TopologyDescription; constructor(message: string, reason: TopologyDescription); get name(): string; } /** * An error signifying a client-side server selection error * @public * @category Error */ export declare class MongoServerSelectionError extends MongoSystemError { constructor(message: string, reason: TopologyDescription); get name(): string; } /** * An error thrown when the server reports a writeConcernError * @public * @category Error */ export declare class MongoWriteConcernError extends MongoServerError { /** The result document (provided if ok: 1) */ result?: Document; constructor(message: ErrorDescription, result?: Document); get name(): string; } export declare function needsRetryableWriteLabel(error: Error, maxWireVersion: number): boolean; export declare function isRetryableWriteError(error: MongoError): boolean; /** Determines whether an error is something the driver should attempt to retry */ export declare function isRetryableReadError(error: MongoError): boolean; export declare function isNodeShuttingDownError(err: MongoError): boolean; /** * 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 */ export declare function isSDAMUnrecoverableError(error: MongoError): boolean; export declare function isNetworkTimeoutError(err: MongoError): err is MongoNetworkError; export declare function isResumableError(error?: Error, wireVersion?: number): boolean; export {}; //# sourceMappingURL=error.d.ts.map