Skip to content

Commit 9ce03bf

Browse files
committed
chore: removed sysexits
1 parent 56f299d commit 9ce03bf

File tree

9 files changed

+2
-136
lines changed

9 files changed

+2
-136
lines changed

src/RPCServer.ts

-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import * as rpcEvents from './events';
2929
import * as rpcUtils from './utils';
3030
import * as rpcErrors from './errors';
3131
import * as rpcUtilsMiddleware from './utils';
32-
import sysexits from './errors/sysexits';
3332
import { never } from './errors';
3433

3534
const cleanupReason = Symbol('CleanupReason');
@@ -305,7 +304,6 @@ class RPCServer extends EventTarget {
305304
controller.enqueue(value);
306305
} catch (e) {
307306
const rpcError: JSONRPCError = {
308-
code: e.exitCode ?? sysexits.UNKNOWN,
309307
message: e.description ?? '',
310308
data: rpcUtils.fromError(e, this.sensitive),
311309
};
@@ -578,7 +576,6 @@ class RPCServer extends EventTarget {
578576
);
579577
} catch (e) {
580578
const rpcError: JSONRPCError = {
581-
code: e.exitCode ?? sysexits.UNKNOWN,
582579
message: e.description ?? '',
583580
data: rpcUtils.fromError(e, this.sensitive),
584581
};

src/errors/errors.ts

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import type { Class } from '@matrixai/errors';
22
import type { JSONValue } from '@/types';
33
import { AbstractError } from '@matrixai/errors';
4-
import sysexits from './sysexits';
54

6-
interface RPCError extends Error {
7-
exitCode?: number;
8-
}
5+
interface RPCError extends Error {}
96

107
class ErrorRPC<T> extends Error implements RPCError {
118
constructor(message?: string) {
129
super(message);
1310
this.name = 'ErrorRPC';
1411
this.description = 'Generic Error';
1512
}
16-
exitCode?: number;
1713
description?: string;
1814
}
1915

@@ -22,20 +18,17 @@ class ErrorRPCDestroyed<T> extends ErrorRPC<T> {
2218
super(message); // Call the parent constructor
2319
this.name = 'ErrorRPCDestroyed'; // Optionally set a specific name
2420
this.description = 'Rpc is destroyed'; // Set the specific description
25-
this.exitCode = sysexits.USAGE; // Set the exit code
2621
}
2722
}
2823

2924
class ErrorRPCParse<T> extends ErrorRPC<T> {
3025
static description = 'Failed to parse Buffer stream';
31-
exitCode = sysexits.SOFTWARE;
3226
cause: Error | undefined; // Added this line to hold the cause
3327

3428
constructor(message?: string, options?: { cause: Error }) {
3529
super(message); // Call the parent constructor
3630
this.name = 'ErrorRPCParse'; // Optionally set a specific name
3731
this.description = 'Failed to parse Buffer stream'; // Set the specific description
38-
this.exitCode = sysexits.SOFTWARE; // Set the exit code
3932

4033
// Set the cause if provided in options
4134
if (options && options.cause) {
@@ -49,7 +42,6 @@ class ErrorRPCStopping<T> extends ErrorRPC<T> {
4942
super(message); // Call the parent constructor
5043
this.name = 'ErrorRPCStopping'; // Optionally set a specific name
5144
this.description = 'Rpc is stopping'; // Set the specific description
52-
this.exitCode = sysexits.USAGE; // Set the exit code
5345
}
5446
}
5547

@@ -63,7 +55,6 @@ class ErrorRPCHandlerFailed<T> extends ErrorRPC<T> {
6355
super(message); // Call the parent constructor
6456
this.name = 'ErrorRPCHandlerFailed'; // Optionally set a specific name
6557
this.description = 'Failed to handle stream'; // Set the specific description
66-
this.exitCode = sysexits.SOFTWARE; // Set the exit code
6758

6859
// Set the cause if provided in options
6960
if (options && options.cause) {
@@ -74,15 +65,13 @@ class ErrorRPCHandlerFailed<T> extends ErrorRPC<T> {
7465

7566
class ErrorRPCMessageLength<T> extends ErrorRPC<T> {
7667
static description = 'RPC Message exceeds maximum size';
77-
exitCode = sysexits.DATAERR;
7868
}
7969

8070
class ErrorRPCMissingResponse<T> extends ErrorRPC<T> {
8171
constructor(message?: string) {
8272
super(message);
8373
this.name = 'ErrorRPCMissingResponse';
8474
this.description = 'Stream ended before response';
85-
this.exitCode = sysexits.UNAVAILABLE;
8675
}
8776
}
8877

@@ -97,7 +86,6 @@ class ErrorRPCOutputStreamError<T> extends ErrorRPC<T> {
9786
super(message);
9887
this.name = 'ErrorRPCOutputStreamError';
9988
this.description = 'Output stream failed, unable to send data';
100-
this.exitCode = sysexits.UNAVAILABLE;
10189

10290
// Set the cause if provided in options
10391
if (options && options.cause) {
@@ -108,7 +96,6 @@ class ErrorRPCOutputStreamError<T> extends ErrorRPC<T> {
10896

10997
class ErrorRPCRemote<T> extends ErrorRPC<T> {
11098
static description = 'Remote error from RPC call';
111-
exitCode: number = sysexits.UNAVAILABLE;
11299
metadata: JSONValue | undefined;
113100

114101
constructor(metadata?: JSONValue, message?: string, options?) {
@@ -129,7 +116,6 @@ class ErrorRPCRemote<T> extends ErrorRPC<T> {
129116
isNaN(Date.parse(json.data.timestamp)) ||
130117
typeof json.data.metadata !== 'object' ||
131118
typeof json.data.data !== 'object' ||
132-
typeof json.data.exitCode !== 'number' ||
133119
('stack' in json.data && typeof json.data.stack !== 'string')
134120
) {
135121
throw new TypeError(`Cannot decode JSON to ${this.name}`);
@@ -143,7 +129,6 @@ class ErrorRPCRemote<T> extends ErrorRPC<T> {
143129
data: json.data.data,
144130
cause: json.data.cause,
145131
});
146-
e.exitCode = json.data.exitCode;
147132
e.stack = json.data.stack;
148133
return e;
149134
}
@@ -152,7 +137,6 @@ class ErrorRPCRemote<T> extends ErrorRPC<T> {
152137
type: this.name,
153138
data: {
154139
description: this.description,
155-
exitCode: this.exitCode,
156140
},
157141
};
158142
}
@@ -163,7 +147,6 @@ class ErrorRPCStreamEnded<T> extends ErrorRPC<T> {
163147
super(message);
164148
this.name = 'ErrorRPCStreamEnded';
165149
this.description = 'Handled stream has ended';
166-
this.exitCode = sysexits.NOINPUT;
167150
}
168151
}
169152

@@ -172,7 +155,6 @@ class ErrorRPCTimedOut<T> extends ErrorRPC<T> {
172155
super(message);
173156
this.name = 'ErrorRPCTimedOut';
174157
this.description = 'RPC handler has timed out';
175-
this.exitCode = sysexits.UNAVAILABLE;
176158
}
177159
}
178160

@@ -181,7 +163,6 @@ class ErrorUtilsUndefinedBehaviour<T> extends ErrorRPC<T> {
181163
super(message);
182164
this.name = 'ErrorUtilsUndefinedBehaviour';
183165
this.description = 'You should never see this error';
184-
this.exitCode = sysexits.SOFTWARE;
185166
}
186167
}
187168
export function never(): never {
@@ -194,7 +175,6 @@ class ErrorRPCMethodNotImplemented<T> extends ErrorRPC<T> {
194175
this.name = 'ErrorRPCMethodNotImplemented';
195176
this.description =
196177
'This abstract method must be implemented in a derived class';
197-
this.exitCode = sysexits.USAGE; // Or another suitable exit code
198178
}
199179
}
200180

src/errors/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export * from './sysexits';
21
export * from './errors';

src/errors/sysexits.ts

-91
This file was deleted.

src/types.ts

-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ type JSONRPCResponseError = {
110110
* This is a JSON RPC error object, it encodes the error data for the JSONRPCResponseError object.
111111
*/
112112
type JSONRPCError = {
113-
/**
114-
* A Number that indicates the error type that occurred.
115-
* This MUST be an integer.
116-
*/
117-
code: number;
118113
/**
119114
* A String providing a short description of the error.
120115
* The message SHOULD be limited to a concise single sentence.

src/utils/utils.ts

-9
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ function parseJSONRPCError(message: unknown): JSONRPCError {
149149
if (!isObject(message)) {
150150
throw new rpcErrors.ErrorRPCParse('must be a JSON POJO');
151151
}
152-
if (!('code' in message)) {
153-
throw new rpcErrors.ErrorRPCParse('`code` property must be defined');
154-
}
155-
if (typeof message.code !== 'number') {
156-
throw new rpcErrors.ErrorRPCParse('`code` property must be a number');
157-
}
158152
if (!('message' in message)) {
159153
throw new rpcErrors.ErrorRPCParse('`message` property must be defined');
160154
}
@@ -369,9 +363,6 @@ function toError(errorData, metadata?: JSONValue): ErrorRPCRemote<unknown> {
369363
const remoteError = new ErrorRPCRemote(metadata, error.message, {
370364
cause: error,
371365
});
372-
if (error instanceof ErrorRPC) {
373-
remoteError.exitCode = error.exitCode as number;
374-
}
375366
return remoteError;
376367
}
377368

tests/RPC.test.ts

-3
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,6 @@ describe('RPC', () => {
443443
const rejection = await callProm;
444444
expect(rejection).toBeInstanceOf(rpcErrors.ErrorRPCRemote);
445445

446-
// The error should have specific properties
447-
expect(rejection).toMatchObject({ exitCode: 69 });
448-
449446
// Cleanup
450447
await rpcServer.destroy();
451448
await rpcClient.destroy();

tests/RPCServer.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ describe(`${RPCServer.name}`, () => {
780780
jsonrpc: '2.0',
781781
id: null,
782782
error: {
783-
code: 1,
784783
message: 'failure of some kind',
785784
},
786785
};

tests/utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,11 @@ const jsonRpcErrorArb = (
149149
fc
150150
.record(
151151
{
152-
code: fc.integer(),
153152
message: fc.string(),
154153
data: error.map((e) => fromError(e, sensitive)),
155154
},
156155
{
157-
requiredKeys: ['code', 'message'],
156+
requiredKeys: ['message'],
158157
},
159158
)
160159
.noShrink() as fc.Arbitrary<JSONRPCError>;

0 commit comments

Comments
 (0)