Skip to content

Commit

Permalink
feat(NODE-3419): define MongoRuntimeError children (#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
andymina committed Jul 13, 2021
1 parent ead7920 commit eadeb01
Showing 1 changed file with 233 additions and 6 deletions.
239 changes: 233 additions & 6 deletions src/error.ts
Expand Up @@ -202,7 +202,6 @@ export class MongoRuntimeError extends MongoDriverError {
* An error generated when a batch command is reexecuted after one of the commands in the batch
* has failed
*
*
* @public
* @category Error
*/
Expand All @@ -216,11 +215,60 @@ export class MongoBatchReExecutionError extends MongoRuntimeError {
}
}

/**
* An error generated when the user supplies an incorrect URI to the driver.
*
* @public
* @category Error
*/
export class MongoURIError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoURIError';
}
}

/**
* An error generated when the driver fails to compress data
* before sending it to the server.
*
* @public
* @category Error
*/
export class MongoCompressionError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoCompressionError';
}
}

/**
* An error generated when the driver fails to decompress
* data received from the server.
*
* @public
* @category Error
*/
export class MongoDecompressionError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return '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
*/
Expand All @@ -234,11 +282,61 @@ export class MongoNotConnectedError extends MongoRuntimeError {
}
}

/**
* 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 class MongoTransactionError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoTransactionError';
}
}

/**
* An error generated when the user attempts to operate
* on a session that has expired or has been closed.
*
* @public
* @category Error
*/
export class MongoExpiredSessionError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoExpiredSessionError';
}
}

/**
* A error generated when the user attempts to authenticate
* via Kerberos, but fails to connect to the Kerberos client.
*
* @public
* @category Error
*/
export class MongoKerberosError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoKerberosError';
}
}

/**
* An error thrown when the user attempts to operate on a cursor that is in a state which does not
* support the attempted operation.
*
*
* @public
* @category Error
*/
Expand All @@ -253,8 +351,39 @@ export class MongoCursorError extends MongoRuntimeError {
}

/**
* An error thrown when the user calls a function or method not supported on a tailable cursor
* An error generated when a stream operation fails to execute.
*
* @public
* @category Error
*/
export class MongoStreamError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoStreamError';
}
}

/**
* An error generated when a ChangeStream operation fails to execute.
*
* @public
* @category Error
*/
export class MongoChangeStreamError extends MongoStreamError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoChangeStreamError';
}
}

/**
* An error thrown when the user calls a function or method not supported on a tailable cursor
*
* @public
* @category Error
Expand All @@ -269,11 +398,42 @@ export class MongoTailableCursorError extends MongoCursorError {
}
}

/** An error generated when a GridFSStream operation fails to execute.
*
* @public
* @category Error
*/
export class MongoGridFSStreamError extends MongoStreamError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoGridFSStreamError';
}
}

/**
* An error generated when a malformed or invalid chunk is
* encountered when reading from a GridFSStream.
*
* @public
* @category Error
*/
export class MongoGridFSChunkError extends MongoStreamError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoGridFSChunkError';
}
}

/**
* An error thrown when the user attempts to add options to a cursor that has already been
* initialized
*
*
* @public
* @category Error
*/
Expand All @@ -288,8 +448,41 @@ export class MongoCursorInUseError extends MongoCursorError {
}

/**
* An error thrown when an attempt is made to read from a cursor that has been exhausted
* An error generated when an attempt is made to access a resource
* which has already been or will be closed/destroyed.
*
* @public
* @category Error
*/
export class MongoResourceClosedError extends MongoRuntimeError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoResourceClosedError';
}
}

/**
* An error generated when an attempt is made to operate
* on a closed/closing server.
*
* @public
* @category Error
*/
export class MongoServerClosedError extends MongoResourceClosedError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoServerClosedError';
}
}

/**
* An error thrown when an attempt is made to read from a cursor that has been exhausted
*
* @public
* @category Error
Expand All @@ -304,6 +497,40 @@ export class MongoCursorExhaustedError extends MongoCursorError {
}
}

/**
* An error generated when an attempt is made to operate
* on a closed/closing stream.
*
* @public
* @category Error
*/
export class MongoStreamClosedError extends MongoResourceClosedError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoStreamClosedError';
}
}

/**
* An error generated when an attempt is made to operate on a
* dropped, or otherwise unavailable, database.
*
* @public
* @category Error
*/
export class MongoTopologyClosedError extends MongoResourceClosedError {
constructor(message: string) {
super(message);
}

get name(): string {
return 'MongoTopologyClosedError';
}
}

/** @internal */
const kBeforeHandshake = Symbol('beforeHandshake');
export function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean {
Expand Down

0 comments on commit eadeb01

Please sign in to comment.