CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
error.ts1572 linesDownload Raw Back to src
1import type { Document } from './bson';2import {3  type ClientBulkWriteError,4  type ClientBulkWriteResult5} from './operations/client_bulk_write/common';6import type { ServerType } from './sdam/common';7import type { TopologyVersion } from './sdam/server_description';8import type { TopologyDescription } from './sdam/topology_description';9 10/** @public */11export type AnyError = MongoError | Error;12 13/**14 * @internal15 * The legacy error message from the server that indicates the node is not a writable primary16 * https://github.com/mongodb/specifications/blob/921232976f9913cf17415b5ef937ee772e45e6ae/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#not-writable-primary-and-node-is-recovering17 */18export const LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = new RegExp('not master', 'i');19 20/**21 * @internal22 * The legacy error message from the server that indicates the node is not a primary or secondary23 * https://github.com/mongodb/specifications/blob/921232976f9913cf17415b5ef937ee772e45e6ae/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#not-writable-primary-and-node-is-recovering24 */25export const LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = new RegExp(26  'not master or secondary',27  'i'28);29 30/**31 * @internal32 * The error message from the server that indicates the node is recovering33 * https://github.com/mongodb/specifications/blob/921232976f9913cf17415b5ef937ee772e45e6ae/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md#not-writable-primary-and-node-is-recovering34 */35export const NODE_IS_RECOVERING_ERROR_MESSAGE = new RegExp('node is recovering', 'i');36 37/** @internal MongoDB Error Codes */38export const MONGODB_ERROR_CODES = Object.freeze({39  HostUnreachable: 6,40  HostNotFound: 7,41  AuthenticationFailed: 18,42  NetworkTimeout: 89,43  ShutdownInProgress: 91,44  PrimarySteppedDown: 189,45  ExceededTimeLimit: 262,46  SocketException: 9001,47  NotWritablePrimary: 10107,48  InterruptedAtShutdown: 11600,49  InterruptedDueToReplStateChange: 11602,50  NotPrimaryNoSecondaryOk: 13435,51  NotPrimaryOrSecondary: 13436,52  StaleShardVersion: 63,53  StaleEpoch: 150,54  StaleConfig: 13388,55  RetryChangeStream: 234,56  FailedToSatisfyReadPreference: 133,57  CursorNotFound: 43,58  LegacyNotPrimary: 10058,59  // WriteConcernTimeout is WriteConcernFailed on pre-8.1 servers60  WriteConcernTimeout: 64,61  NamespaceNotFound: 26,62  IllegalOperation: 20,63  MaxTimeMSExpired: 50,64  UnknownReplWriteConcern: 79,65  UnsatisfiableWriteConcern: 100,66  Reauthenticate: 391,67  ReadConcernMajorityNotAvailableYet: 13468} as const);69 70// From spec https://github.com/mongodb/specifications/blob/921232976f9913cf17415b5ef937ee772e45e6ae/source/change-streams/change-streams.md#resumable-error71export const GET_MORE_RESUMABLE_CODES = new Set<number>([72  MONGODB_ERROR_CODES.HostUnreachable,73  MONGODB_ERROR_CODES.HostNotFound,74  MONGODB_ERROR_CODES.NetworkTimeout,75  MONGODB_ERROR_CODES.ShutdownInProgress,76  MONGODB_ERROR_CODES.PrimarySteppedDown,77  MONGODB_ERROR_CODES.ExceededTimeLimit,78  MONGODB_ERROR_CODES.SocketException,79  MONGODB_ERROR_CODES.NotWritablePrimary,80  MONGODB_ERROR_CODES.InterruptedAtShutdown,81  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,82  MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,83  MONGODB_ERROR_CODES.NotPrimaryOrSecondary,84  MONGODB_ERROR_CODES.StaleShardVersion,85  MONGODB_ERROR_CODES.StaleEpoch,86  MONGODB_ERROR_CODES.StaleConfig,87  MONGODB_ERROR_CODES.RetryChangeStream,88  MONGODB_ERROR_CODES.FailedToSatisfyReadPreference,89  MONGODB_ERROR_CODES.CursorNotFound90]);91 92/** @public */93export const MongoErrorLabel = Object.freeze({94  RetryableWriteError: 'RetryableWriteError',95  TransientTransactionError: 'TransientTransactionError',96  UnknownTransactionCommitResult: 'UnknownTransactionCommitResult',97  ResumableChangeStreamError: 'ResumableChangeStreamError',98  HandshakeError: 'HandshakeError',99  ResetPool: 'ResetPool',100  PoolRequstedRetry: 'PoolRequstedRetry',101  InterruptInUseConnections: 'InterruptInUseConnections',102  NoWritesPerformed: 'NoWritesPerformed'103} as const);104 105/** @public */106export type MongoErrorLabel = (typeof MongoErrorLabel)[keyof typeof MongoErrorLabel];107 108/** @public */109export interface ErrorDescription extends Document {110  message?: string;111  errmsg?: string;112  $err?: string;113  errorLabels?: string[];114  errInfo?: Document;115}116 117function isAggregateError(e: unknown): e is Error & { errors: Error[] } {118  return e != null && typeof e === 'object' && 'errors' in e && Array.isArray(e.errors);119}120 121/**122 * @public123 * @category Error124 *125 * @privateRemarks126 * mongodb-client-encryption has a dependency on this error, it uses the constructor with a string argument127 */128export class MongoError extends Error {129  /** @internal */130  private readonly errorLabelSet: Set<string> = new Set();131  public get errorLabels(): string[] {132    return Array.from(this.errorLabelSet);133  }134 135  /**136   * This is a number in MongoServerError and a string in MongoDriverError137   * @privateRemarks138   * Define the type override on the subclasses when we can use the override keyword139   */140  code?: number | string;141  topologyVersion?: TopologyVersion;142  connectionGeneration?: number;143  override cause?: Error;144 145  /**146   * **Do not use this constructor!**147   *148   * Meant for internal use only.149   *150   * @remarks151   * This class is only meant to be constructed within the driver. This constructor is152   * not subject to semantic versioning compatibility guarantees and may change at any time.153   *154   * @public155   **/156  constructor(message: string, options?: { cause?: Error }) {157    super(message, options);158  }159 160  /** @internal */161  static buildErrorMessage(e: unknown): string {162    if (typeof e === 'string') {163      return e;164    }165    if (isAggregateError(e) && e.message.length === 0) {166      return e.errors.length === 0167        ? 'AggregateError has an empty errors array. Please check the `cause` property for more information.'168        : e.errors.map(({ message }) => message).join(', ');169    }170 171    return e != null && typeof e === 'object' && 'message' in e && typeof e.message === 'string'172      ? e.message173      : 'empty error message';174  }175 176  override get name(): string {177    return 'MongoError';178  }179 180  /** Legacy name for server error responses */181  get errmsg(): string {182    return this.message;183  }184 185  /**186   * Checks the error to see if it has an error label187   *188   * @param label - The error label to check for189   * @returns returns true if the error has the provided error label190   */191  hasErrorLabel(label: string): boolean {192    return this.errorLabelSet.has(label);193  }194 195  addErrorLabel(label: string): void {196    this.errorLabelSet.add(label);197  }198}199 200/**201 * An error coming from the mongo server202 *203 * @public204 * @category Error205 */206export class MongoServerError extends MongoError {207  /** Raw error result document returned by server. */208  errorResponse: ErrorDescription;209  codeName?: string;210  writeConcernError?: Document;211  errInfo?: Document;212  ok?: number;213  [key: string]: any;214 215  /**216   * **Do not use this constructor!**217   *218   * Meant for internal use only.219   *220   * @remarks221   * This class is only meant to be constructed within the driver. This constructor is222   * not subject to semantic versioning compatibility guarantees and may change at any time.223   *224   * @public225   **/226  constructor(message: ErrorDescription) {227    super(message.message || message.errmsg || message.$err || 'n/a');228 229    if (message.errorLabels) {230      for (const label of message.errorLabels) this.addErrorLabel(label);231    }232 233    this.errorResponse = message;234 235    for (const name in message) {236      if (237        name !== 'errorLabels' &&238        name !== 'errmsg' &&239        name !== 'message' &&240        name !== 'errorResponse'241      ) {242        this[name] = message[name];243      }244    }245  }246 247  override get name(): string {248    return 'MongoServerError';249  }250}251 252/**253 * An error generated by the driver254 *255 * @public256 * @category Error257 */258export class MongoDriverError extends MongoError {259  /**260   * **Do not use this constructor!**261   *262   * Meant for internal use only.263   *264   * @remarks265   * This class is only meant to be constructed within the driver. This constructor is266   * not subject to semantic versioning compatibility guarantees and may change at any time.267   *268   * @public269   **/270  constructor(message: string, options?: { cause?: Error }) {271    super(message, options);272  }273 274  override get name(): string {275    return 'MongoDriverError';276  }277}278 279/**280 * An error generated when the driver API is used incorrectly281 *282 * @privateRemarks283 * Should **never** be directly instantiated284 *285 * @public286 * @category Error287 */288 289export class MongoAPIError extends MongoDriverError {290  /**291   * **Do not use this constructor!**292   *293   * Meant for internal use only.294   *295   * @remarks296   * This class is only meant to be constructed within the driver. This constructor is297   * not subject to semantic versioning compatibility guarantees and may change at any time.298   *299   * @public300   **/301  constructor(message: string, options?: { cause?: Error }) {302    super(message, options);303  }304 305  override get name(): string {306    return 'MongoAPIError';307  }308}309 310/**311 * An error generated when the driver encounters unexpected input312 * or reaches an unexpected/invalid internal state.313 *314 * @privateRemarks315 * Should **never** be directly instantiated.316 *317 * @public318 * @category Error319 */320export class MongoRuntimeError extends MongoDriverError {321  /**322   * **Do not use this constructor!**323   *324   * Meant for internal use only.325   *326   * @remarks327   * This class is only meant to be constructed within the driver. This constructor is328   * not subject to semantic versioning compatibility guarantees and may change at any time.329   *330   * @public331   **/332  constructor(message: string, options?: { cause?: Error }) {333    super(message, options);334  }335 336  override get name(): string {337    return 'MongoRuntimeError';338  }339}340 341/**342 * An error generated when a primary server is marked stale, never directly thrown343 *344 * @public345 * @category Error346 */347export class MongoStalePrimaryError extends MongoRuntimeError {348  /**349   * **Do not use this constructor!**350   *351   * Meant for internal use only.352   *353   * @remarks354   * This class is only meant to be constructed within the driver. This constructor is355   * not subject to semantic versioning compatibility guarantees and may change at any time.356   *357   * @public358   **/359  constructor(message: string, options?: { cause?: Error }) {360    super(message, options);361  }362 363  override get name(): string {364    return 'MongoStalePrimaryError';365  }366}367 368/**369 * An error generated when a batch command is re-executed after one of the commands in the batch370 * has failed371 *372 * @public373 * @category Error374 */375export class MongoBatchReExecutionError extends MongoAPIError {376  /**377   * **Do not use this constructor!**378   *379   * Meant for internal use only.380   *381   * @remarks382   * This class is only meant to be constructed within the driver. This constructor is383   * not subject to semantic versioning compatibility guarantees and may change at any time.384   *385   * @public386   **/387  constructor(message = 'This batch has already been executed, create new batch to execute') {388    super(message);389  }390 391  override get name(): string {392    return 'MongoBatchReExecutionError';393  }394}395 396/**397 * An error generated when the driver fails to decompress398 * data received from the server.399 *400 * @public401 * @category Error402 */403export class MongoDecompressionError extends MongoRuntimeError {404  /**405   * **Do not use this constructor!**406   *407   * Meant for internal use only.408   *409   * @remarks410   * This class is only meant to be constructed within the driver. This constructor is411   * not subject to semantic versioning compatibility guarantees and may change at any time.412   *413   * @public414   **/415  constructor(message: string) {416    super(message);417  }418 419  override get name(): string {420    return 'MongoDecompressionError';421  }422}423 424/**425 * An error thrown when the user attempts to operate on a database or collection through a MongoClient426 * that has not yet successfully called the "connect" method427 *428 * @public429 * @category Error430 */431export class MongoNotConnectedError extends MongoAPIError {432  /**433   * **Do not use this constructor!**434   *435   * Meant for internal use only.436   *437   * @remarks438   * This class is only meant to be constructed within the driver. This constructor is439   * not subject to semantic versioning compatibility guarantees and may change at any time.440   *441   * @public442   **/443  constructor(message: string) {444    super(message);445  }446 447  override get name(): string {448    return 'MongoNotConnectedError';449  }450}451 452/**453 * An error generated when the user makes a mistake in the usage of transactions.454 * (e.g. attempting to commit a transaction with a readPreference other than primary)455 *456 * @public457 * @category Error458 */459export class MongoTransactionError extends MongoAPIError {460  /**461   * **Do not use this constructor!**462   *463   * Meant for internal use only.464   *465   * @remarks466   * This class is only meant to be constructed within the driver. This constructor is467   * not subject to semantic versioning compatibility guarantees and may change at any time.468   *469   * @public470   **/471  constructor(message: string) {472    super(message);473  }474 475  override get name(): string {476    return 'MongoTransactionError';477  }478}479 480/**481 * An error generated when the user attempts to operate482 * on a session that has expired or has been closed.483 *484 * @public485 * @category Error486 */487export class MongoExpiredSessionError extends MongoAPIError {488  /**489   * **Do not use this constructor!**490   *491   * Meant for internal use only.492   *493   * @remarks494   * This class is only meant to be constructed within the driver. This constructor is495   * not subject to semantic versioning compatibility guarantees and may change at any time.496   *497   * @public498   **/499  constructor(message = 'Cannot use a session that has ended') {500    super(message);501  }502 503  override get name(): string {504    return 'MongoExpiredSessionError';505  }506}507 508/**509 * A error generated when the user attempts to authenticate510 * via Kerberos, but fails to connect to the Kerberos client.511 *512 * @public513 * @category Error514 */515export class MongoKerberosError extends MongoRuntimeError {516  /**517   * **Do not use this constructor!**518   *519   * Meant for internal use only.520   *521   * @remarks522   * This class is only meant to be constructed within the driver. This constructor is523   * not subject to semantic versioning compatibility guarantees and may change at any time.524   *525   * @public526   **/527  constructor(message: string) {528    super(message);529  }530 531  override get name(): string {532    return 'MongoKerberosError';533  }534}535 536/**537 * A error generated when the user attempts to authenticate538 * via AWS, but fails539 *540 * @public541 * @category Error542 */543export class MongoAWSError extends MongoRuntimeError {544  /**545   * **Do not use this constructor!**546   *547   * Meant for internal use only.548   *549   * @remarks550   * This class is only meant to be constructed within the driver. This constructor is551   * not subject to semantic versioning compatibility guarantees and may change at any time.552   *553   * @public554   **/555  constructor(message: string, options?: { cause?: Error }) {556    super(message, options);557  }558 559  override get name(): string {560    return 'MongoAWSError';561  }562}563 564/**565 * A error generated when the user attempts to authenticate566 * via OIDC callbacks, but fails.567 *568 * @public569 * @category Error570 */571export class MongoOIDCError extends MongoRuntimeError {572  /**573   * **Do not use this constructor!**574   *575   * Meant for internal use only.576   *577   * @remarks578   * This class is only meant to be constructed within the driver. This constructor is579   * not subject to semantic versioning compatibility guarantees and may change at any time.580   *581   * @public582   **/583  constructor(message: string) {584    super(message);585  }586 587  override get name(): string {588    return 'MongoOIDCError';589  }590}591 592/**593 * A error generated when the user attempts to authenticate594 * via Azure, but fails.595 *596 * @public597 * @category Error598 */599export class MongoAzureError extends MongoOIDCError {600  /**601   * **Do not use this constructor!**602   *603   * Meant for internal use only.604   *605   * @remarks606   * This class is only meant to be constructed within the driver. This constructor is607   * not subject to semantic versioning compatibility guarantees and may change at any time.608   *609   * @public610   **/611  constructor(message: string) {612    super(message);613  }614 615  override get name(): string {616    return 'MongoAzureError';617  }618}619 620/**621 * A error generated when the user attempts to authenticate622 * via GCP, but fails.623 *624 * @public625 * @category Error626 */627export class MongoGCPError extends MongoOIDCError {628  /**629   * **Do not use this constructor!**630   *631   * Meant for internal use only.632   *633   * @remarks634   * This class is only meant to be constructed within the driver. This constructor is635   * not subject to semantic versioning compatibility guarantees and may change at any time.636   *637   * @public638   **/639  constructor(message: string) {640    super(message);641  }642 643  override get name(): string {644    return 'MongoGCPError';645  }646}647 648/**649 * An error indicating that an error occurred when executing the bulk write.650 *651 * @public652 * @category Error653 */654export class MongoClientBulkWriteError extends MongoServerError {655  /**656   * Write concern errors that occurred while executing the bulk write. This list may have657   * multiple items if more than one server command was required to execute the bulk write.658   */659  writeConcernErrors: Document[];660  /**661   * Errors that occurred during the execution of individual write operations. This map will662   * contain at most one entry if the bulk write was ordered.663   */664  writeErrors: Map<number, ClientBulkWriteError>;665  /**666   * The results of any successful operations that were performed before the error was667   * encountered.668   */669  partialResult?: ClientBulkWriteResult;670 671  /**672   * Initialize the client bulk write error.673   * @param message - The error message.674   */675  constructor(message: ErrorDescription) {676    super(message);677    this.writeConcernErrors = [];678    this.writeErrors = new Map();679  }680 681  override get name(): string {682    return 'MongoClientBulkWriteError';683  }684}685 686/**687 * An error indicating that an error occurred when processing bulk write results.688 *689 * @public690 * @category Error691 */692export class MongoClientBulkWriteCursorError extends MongoRuntimeError {693  /**694   * **Do not use this constructor!**695   *696   * Meant for internal use only.697   *698   * @remarks699   * This class is only meant to be constructed within the driver. This constructor is700   * not subject to semantic versioning compatibility guarantees and may change at any time.701   *702   * @public703   **/704  constructor(message: string) {705    super(message);706  }707 708  override get name(): string {709    return 'MongoClientBulkWriteCursorError';710  }711}712 713/**714 * An error indicating that an error occurred on the client when executing a client bulk write.715 *716 * @public717 * @category Error718 */719export class MongoClientBulkWriteExecutionError extends MongoRuntimeError {720  /**721   * **Do not use this constructor!**722   *723   * Meant for internal use only.724   *725   * @remarks726   * This class is only meant to be constructed within the driver. This constructor is727   * not subject to semantic versioning compatibility guarantees and may change at any time.728   *729   * @public730   **/731  constructor(message: string) {732    super(message);733  }734 735  override get name(): string {736    return 'MongoClientBulkWriteExecutionError';737  }738}739 740/**741 * An error generated when a ChangeStream operation fails to execute.742 *743 * @public744 * @category Error745 */746export class MongoChangeStreamError extends MongoRuntimeError {747  /**748   * **Do not use this constructor!**749   *750   * Meant for internal use only.751   *752   * @remarks753   * This class is only meant to be constructed within the driver. This constructor is754   * not subject to semantic versioning compatibility guarantees and may change at any time.755   *756   * @public757   **/758  constructor(message: string) {759    super(message);760  }761 762  override get name(): string {763    return 'MongoChangeStreamError';764  }765}766 767/**768 * An error thrown when the user calls a function or method not supported on a tailable cursor769 *770 * @public771 * @category Error772 */773export class MongoTailableCursorError extends MongoAPIError {774  /**775   * **Do not use this constructor!**776   *777   * Meant for internal use only.778   *779   * @remarks780   * This class is only meant to be constructed within the driver. This constructor is781   * not subject to semantic versioning compatibility guarantees and may change at any time.782   *783   * @public784   **/785  constructor(message = 'Tailable cursor does not support this operation') {786    super(message);787  }788 789  override get name(): string {790    return 'MongoTailableCursorError';791  }792}793 794/** An error generated when a GridFSStream operation fails to execute.795 *796 * @public797 * @category Error798 */799export class MongoGridFSStreamError extends MongoRuntimeError {800  /**801   * **Do not use this constructor!**802   *803   * Meant for internal use only.804   *805   * @remarks806   * This class is only meant to be constructed within the driver. This constructor is807   * not subject to semantic versioning compatibility guarantees and may change at any time.808   *809   * @public810   **/811  constructor(message: string) {812    super(message);813  }814 815  override get name(): string {816    return 'MongoGridFSStreamError';817  }818}819 820/**821 * An error generated when a malformed or invalid chunk is822 * encountered when reading from a GridFSStream.823 *824 * @public825 * @category Error826 */827export class MongoGridFSChunkError extends MongoRuntimeError {828  /**829   * **Do not use this constructor!**830   *831   * Meant for internal use only.832   *833   * @remarks834   * This class is only meant to be constructed within the driver. This constructor is835   * not subject to semantic versioning compatibility guarantees and may change at any time.836   *837   * @public838   **/839  constructor(message: string) {840    super(message);841  }842 843  override get name(): string {844    return 'MongoGridFSChunkError';845  }846}847 848/**849 * An error generated when a **parsable** unexpected response comes from the server.850 * This is generally an error where the driver in a state expecting a certain behavior to occur in851 * the next message from MongoDB but it receives something else.852 * This error **does not** represent an issue with wire message formatting.853 *854 * #### Example855 * When an operation fails, it is the driver's job to retry it. It must perform serverSelection856 * again to make sure that it attempts the operation against a server in a good state. If server857 * selection returns a server that does not support retryable operations, this error is used.858 * This scenario is unlikely as retryable support would also have been determined on the first attempt859 * but it is possible the state change could report a selectable server that does not support retries.860 *861 * @public862 * @category Error863 */864export class MongoUnexpectedServerResponseError extends MongoRuntimeError {865  /**866   * **Do not use this constructor!**867   *868   * Meant for internal use only.869   *870   * @remarks871   * This class is only meant to be constructed within the driver. This constructor is872   * not subject to semantic versioning compatibility guarantees and may change at any time.873   *874   * @public875   **/876  constructor(message: string, options?: { cause?: Error }) {877    super(message, options);878  }879 880  override get name(): string {881    return 'MongoUnexpectedServerResponseError';882  }883}884 885/**886 * @public887 * @category Error888 *889 * The `MongoOperationTimeoutError` class represents an error that occurs when an operation could not be completed within the specified `timeoutMS`.890 * It is generated by the driver in support of the "client side operation timeout" feature so inherits from `MongoDriverError`.891 * When `timeoutMS` is enabled `MongoServerError`s relating to `MaxTimeExpired` errors will be converted to `MongoOperationTimeoutError`892 *893 * @example894 * ```ts895 * try {896 *   await blogs.insertOne(blogPost, { timeoutMS: 60_000 })897 * } catch (error) {898 *   if (error instanceof MongoOperationTimeoutError) {899 *     console.log(`Oh no! writer's block!`, error);900 *   }901 * }902 * ```903 */904export class MongoOperationTimeoutError extends MongoDriverError {905  override get name(): string {906    return 'MongoOperationTimeoutError';907  }908}909 910/**911 * An error thrown when the user attempts to add options to a cursor that has already been912 * initialized913 *914 * @public915 * @category Error916 */917export class MongoCursorInUseError extends MongoAPIError {918  /**919   * **Do not use this constructor!**920   *921   * Meant for internal use only.922   *923   * @remarks924   * This class is only meant to be constructed within the driver. This constructor is925   * not subject to semantic versioning compatibility guarantees and may change at any time.926   *927   * @public928   **/929  constructor(message = 'Cursor is already initialized') {930    super(message);931  }932 933  override get name(): string {934    return 'MongoCursorInUseError';935  }936}937 938/**939 * An error generated when an attempt is made to operate940 * on a closed/closing server.941 *942 * @public943 * @category Error944 */945export class MongoServerClosedError extends MongoAPIError {946  /**947   * **Do not use this constructor!**948   *949   * Meant for internal use only.950   *951   * @remarks952   * This class is only meant to be constructed within the driver. This constructor is953   * not subject to semantic versioning compatibility guarantees and may change at any time.954   *955   * @public956   **/957  constructor(message = 'Server is closed') {958    super(message);959  }960 961  override get name(): string {962    return 'MongoServerClosedError';963  }964}965 966/**967 * An error thrown when an attempt is made to read from a cursor that has been exhausted968 *969 * @public970 * @category Error971 */972export class MongoCursorExhaustedError extends MongoAPIError {973  /**974   * **Do not use this constructor!**975   *976   * Meant for internal use only.977   *978   * @remarks979   * This class is only meant to be constructed within the driver. This constructor is980   * not subject to semantic versioning compatibility guarantees and may change at any time.981   *982   * @public983   **/984  constructor(message?: string) {985    super(message || 'Cursor is exhausted');986  }987 988  override get name(): string {989    return 'MongoCursorExhaustedError';990  }991}992 993/**994 * An error generated when an attempt is made to operate on a995 * dropped, or otherwise unavailable, database.996 *997 * @public998 * @category Error999 */1000export class MongoTopologyClosedError extends MongoAPIError {1001  /**1002   * **Do not use this constructor!**1003   *1004   * Meant for internal use only.1005   *1006   * @remarks1007   * This class is only meant to be constructed within the driver. This constructor is1008   * not subject to semantic versioning compatibility guarantees and may change at any time.1009   *1010   * @public1011   **/1012  constructor(message = 'Topology is closed') {1013    super(message);1014  }1015 1016  override get name(): string {1017    return 'MongoTopologyClosedError';1018  }1019}1020 1021/**1022 * An error generated when the MongoClient is closed and async1023 * operations are interrupted.1024 *1025 * @public1026 * @category Error1027 */1028export class MongoClientClosedError extends MongoAPIError {1029  /**1030   * **Do not use this constructor!**1031   *1032   * Meant for internal use only.1033   *1034   * @remarks1035   * This class is only meant to be constructed within the driver. This constructor is1036   * not subject to semantic versioning compatibility guarantees and may change at any time.1037   *1038   * @public1039   **/1040  constructor() {1041    super('Operation interrupted because client was closed');1042  }1043 1044  override get name(): string {1045    return 'MongoClientClosedError';1046  }1047}1048 1049/** @public */1050export interface MongoNetworkErrorOptions {1051  /** Indicates the timeout happened before a connection handshake completed */1052  beforeHandshake?: boolean;1053  cause?: Error;1054}1055 1056/**1057 * An error indicating an issue with the network, including TCP errors and timeouts.1058 * @public1059 * @category Error1060 */1061export class MongoNetworkError extends MongoError {1062  /** @internal */1063  public readonly beforeHandshake: boolean;1064 1065  /**1066   * **Do not use this constructor!**1067   *1068   * Meant for internal use only.1069   *1070   * @remarks1071   * This class is only meant to be constructed within the driver. This constructor is1072   * not subject to semantic versioning compatibility guarantees and may change at any time.1073   *1074   * @public1075   **/1076  constructor(message: string, options?: MongoNetworkErrorOptions) {1077    super(message, { cause: options?.cause });1078    this.beforeHandshake = !!options?.beforeHandshake;1079  }1080 1081  override get name(): string {1082    return 'MongoNetworkError';1083  }1084}1085 1086/**1087 * An error indicating a network timeout occurred1088 * @public1089 * @category Error1090 *1091 * @privateRemarks1092 * mongodb-client-encryption has a dependency on this error with an instanceof check1093 */1094export class MongoNetworkTimeoutError extends MongoNetworkError {1095  /**1096   * **Do not use this constructor!**1097   *1098   * Meant for internal use only.1099   *1100   * @remarks1101   * This class is only meant to be constructed within the driver. This constructor is1102   * not subject to semantic versioning compatibility guarantees and may change at any time.1103   *1104   * @public1105   **/1106  constructor(message: string, options?: MongoNetworkErrorOptions) {1107    super(message, options);1108  }1109 1110  override get name(): string {1111    return 'MongoNetworkTimeoutError';1112  }1113}1114 1115/**1116 * An error used when attempting to parse a value (like a connection string)1117 * @public1118 * @category Error1119 */1120export class MongoParseError extends MongoDriverError {1121  /**1122   * **Do not use this constructor!**1123   *1124   * Meant for internal use only.1125   *1126   * @remarks1127   * This class is only meant to be constructed within the driver. This constructor is1128   * not subject to semantic versioning compatibility guarantees and may change at any time.1129   *1130   * @public1131   **/1132  constructor(message: string) {1133    super(message);1134  }1135 1136  override get name(): string {1137    return 'MongoParseError';1138  }1139}1140 1141/**1142 * An error generated when the user supplies malformed or unexpected arguments1143 * or when a required argument or field is not provided.1144 *1145 *1146 * @public1147 * @category Error1148 */1149export class MongoInvalidArgumentError extends MongoAPIError {1150  /**1151   * **Do not use this constructor!**1152   *1153   * Meant for internal use only.1154   *1155   * @remarks1156   * This class is only meant to be constructed within the driver. This constructor is1157   * not subject to semantic versioning compatibility guarantees and may change at any time.1158   *1159   * @public1160   **/1161  constructor(message: string, options?: { cause?: Error }) {1162    super(message, options);1163  }1164 1165  override get name(): string {1166    return 'MongoInvalidArgumentError';1167  }1168}1169 1170/**1171 * An error generated when a feature that is not enabled or allowed for the current server1172 * configuration is used1173 *1174 *1175 * @public1176 * @category Error1177 */1178export class MongoCompatibilityError extends MongoAPIError {1179  /**1180   * **Do not use this constructor!**1181   *1182   * Meant for internal use only.1183   *1184   * @remarks1185   * This class is only meant to be constructed within the driver. This constructor is1186   * not subject to semantic versioning compatibility guarantees and may change at any time.1187   *1188   * @public1189   **/1190  constructor(message: string) {1191    super(message);1192  }1193 1194  override get name(): string {1195    return 'MongoCompatibilityError';1196  }1197}1198 1199/**1200 * An error generated when the user fails to provide authentication credentials before attempting

Showing the first 1,200 of 1572 lines. Download the file for the rest.