-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into NODE-4892-version-tag
- Loading branch information
Showing
15 changed files
with
216 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
/** @public */ | ||
/** | ||
* @public | ||
* `BSONError` objects are thrown when runtime errors occur. | ||
*/ | ||
export class BSONError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
/** | ||
* @internal | ||
* The underlying algorithm for isBSONError may change to improve how strict it is | ||
* about determining if an input is a BSONError. But it must remain backwards compatible | ||
* with previous minors & patches of the current major version. | ||
*/ | ||
protected get bsonError(): true { | ||
return true; | ||
} | ||
|
||
get name(): string { | ||
override get name(): string { | ||
return 'BSONError'; | ||
} | ||
} | ||
|
||
/** @public */ | ||
export class BSONTypeError extends TypeError { | ||
constructor(message: string) { | ||
super(message); | ||
} | ||
|
||
get name(): string { | ||
return 'BSONTypeError'; | ||
/** | ||
* @public | ||
* | ||
* All errors thrown from the BSON library inherit from `BSONError`. | ||
* This method can assist with determining if an error originates from the BSON library | ||
* even if it does not pass an `instanceof` check against this class' constructor. | ||
* | ||
* @param value - any javascript value that needs type checking | ||
*/ | ||
public static isBSONError(value: unknown): value is BSONError { | ||
return ( | ||
value != null && | ||
typeof value === 'object' && | ||
'bsonError' in value && | ||
value.bsonError === true && | ||
// Do not access the following properties, just check existence | ||
'name' in value && | ||
'message' in value && | ||
'stack' in value | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.