Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"prettier"
]
}
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
* text eol=lf
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"overrides": [
{
"files": ["*.*ts?(x)", "*.js?(x)"],
"options": {
"tabWidth": 4,
"singleQuote": true
}
}
]
}
180 changes: 121 additions & 59 deletions README.md

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"coverageReporters": [
"html",
"text",
"cobertura",
"json",
"lcovonly"
],
"coverageReporters": ["html", "text", "cobertura", "json", "lcovonly"],
"coverageThreshold": {
"global": {
"statements": 90,
Expand Down
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
"sideEffects": false,
"scripts": {
"build": "tsc",
"lint": "eslint . --ext .ts",
"prebuild": "npm run format",
"format": "prettier -w . --ignore-path .gitignore",
"format:check": "prettier -c . --ignore-path .gitignore",
"test": "jest",
"docs": "typedoc"
"posttest": "npm run format:check",
"docs": "typedoc",
"predocs": "npm run format"
},
"dependencies": {
"@msgpack/msgpack": "^2.7.2",
Expand All @@ -40,7 +44,9 @@
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"jest": "^28.1.3",
"prettier": "^2.7.1",
"ts-jest": "^28.0.8",
"typed-emitter": "^2.1.0",
"typedoc": "^0.23.10",
Expand Down
64 changes: 50 additions & 14 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export enum ProcedureErrorCodes {
/** An unhandled exception was thrown while attempting to handle the procedure. */
INTERNAL_SERVER_ERROR = 200,
/** An unhandled exception was thrown during procedure execution. */
EXECUTION_ERROR = 201
EXECUTION_ERROR = 201,
}

/**
/**
* A base abstraction of an error relating to a procedure.
* @internal
* @remarks Intended for internal use; may not be exported in future.
Expand Down Expand Up @@ -61,7 +61,10 @@ export class ProcedureUnknownError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'An unhandled exception of unknown origin was thrown while handling the request.', data?: Record<string, unknown>) {
constructor(
message = 'An unhandled exception of unknown origin was thrown while handling the request.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -75,7 +78,10 @@ export class ProcedureInternalClientError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'An unhandled exception was thrown while attempting to call the procedure.', data?: Record<string, unknown>) {
constructor(
message = 'An unhandled exception was thrown while attempting to call the procedure.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -89,7 +95,10 @@ export class ProcedureNotFoundError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'The procedure could not be found at the stated endpoint.', data?: Record<string, unknown>) {
constructor(
message = 'The procedure could not be found at the stated endpoint.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -103,7 +112,10 @@ export class ProcedureCancelledError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'The operation was cancelled by the client.', data?: Record<string, unknown>) {
constructor(
message = 'The operation was cancelled by the client.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -117,7 +129,10 @@ export class ProcedureTimedOutError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'Timed out waiting for the operation to complete.', data?: Record<string, unknown>) {
constructor(
message = 'Timed out waiting for the operation to complete.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -131,7 +146,10 @@ export class ProcedureInvalidResponseError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'The response from the server was invalid.', data?: Record<string, unknown>) {
constructor(
message = 'The response from the server was invalid.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -145,7 +163,10 @@ export class ProcedureInternalServerError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'An unhandled exception was thrown while attempting to handle the procedure.', data?: Record<string, unknown>) {
constructor(
message = 'An unhandled exception was thrown while attempting to handle the procedure.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -159,7 +180,10 @@ export class ProcedureExecutionError extends ProcedureError {
* @param {string} [message] A string indicating the cause of the error.
* @param {Record<string, unknown>} [data] An optional dictionary of data which will be passed to a procedure's caller when thrown.
*/
constructor(message = 'An unhandled exception was thrown during procedure execution.', data?: Record<string, unknown>) {
constructor(
message = 'An unhandled exception was thrown during procedure execution.',
data?: Record<string, unknown>
) {
super(message, data);
}
}
Expand All @@ -174,7 +198,13 @@ export class ProcedureExecutionError extends ProcedureError {
* @remarks Intended for internal use; may not be exported in future.
*/
export function isError(object: unknown): object is Error {
return object instanceof Error || (typeof object === 'object' && object !== null && 'name' in object && 'message' in object);
return (
object instanceof Error ||
(typeof object === 'object' &&
object !== null &&
'name' in object &&
'message' in object)
);
}

/**
Expand All @@ -183,7 +213,13 @@ export function isError(object: unknown): object is Error {
* @returns {object is ProcedureError} `true` if the object conforms to the {@link ProcedureError} interface, otherwise `false`.
*/
export function isProcedureError(object: unknown): object is ProcedureError {
return object instanceof ProcedureError || (isError(object) && object.name.startsWith('Procedure') && object.name.endsWith('Error')
&& 'message' in object
&& 'code' in object && (<{ code: number }>object).code in ProcedureErrorCodes);
return (
object instanceof ProcedureError ||
(isError(object) &&
object.name.startsWith('Procedure') &&
object.name.endsWith('Error') &&
'message' in object &&
'code' in object &&
(<{ code: number }>object).code in ProcedureErrorCodes)
);
}
Loading