1
1
import type { Class } from '@matrixai/errors' ;
2
2
import type { JSONValue } from '@/types' ;
3
3
import { AbstractError } from '@matrixai/errors' ;
4
- import sysexits from './sysexits' ;
5
4
6
- interface RPCError extends Error {
7
- exitCode ?: number ;
8
- }
5
+ interface RPCError extends Error { }
9
6
10
7
class ErrorRPC < T > extends Error implements RPCError {
11
8
constructor ( message ?: string ) {
12
9
super ( message ) ;
13
10
this . name = 'ErrorRPC' ;
14
11
this . description = 'Generic Error' ;
15
12
}
16
- exitCode ?: number ;
17
13
description ?: string ;
18
14
}
19
15
@@ -22,20 +18,17 @@ class ErrorRPCDestroyed<T> extends ErrorRPC<T> {
22
18
super ( message ) ; // Call the parent constructor
23
19
this . name = 'ErrorRPCDestroyed' ; // Optionally set a specific name
24
20
this . description = 'Rpc is destroyed' ; // Set the specific description
25
- this . exitCode = sysexits . USAGE ; // Set the exit code
26
21
}
27
22
}
28
23
29
24
class ErrorRPCParse < T > extends ErrorRPC < T > {
30
25
static description = 'Failed to parse Buffer stream' ;
31
- exitCode = sysexits . SOFTWARE ;
32
26
cause : Error | undefined ; // Added this line to hold the cause
33
27
34
28
constructor ( message ?: string , options ?: { cause : Error } ) {
35
29
super ( message ) ; // Call the parent constructor
36
30
this . name = 'ErrorRPCParse' ; // Optionally set a specific name
37
31
this . description = 'Failed to parse Buffer stream' ; // Set the specific description
38
- this . exitCode = sysexits . SOFTWARE ; // Set the exit code
39
32
40
33
// Set the cause if provided in options
41
34
if ( options && options . cause ) {
@@ -49,7 +42,6 @@ class ErrorRPCStopping<T> extends ErrorRPC<T> {
49
42
super ( message ) ; // Call the parent constructor
50
43
this . name = 'ErrorRPCStopping' ; // Optionally set a specific name
51
44
this . description = 'Rpc is stopping' ; // Set the specific description
52
- this . exitCode = sysexits . USAGE ; // Set the exit code
53
45
}
54
46
}
55
47
@@ -63,7 +55,6 @@ class ErrorRPCHandlerFailed<T> extends ErrorRPC<T> {
63
55
super ( message ) ; // Call the parent constructor
64
56
this . name = 'ErrorRPCHandlerFailed' ; // Optionally set a specific name
65
57
this . description = 'Failed to handle stream' ; // Set the specific description
66
- this . exitCode = sysexits . SOFTWARE ; // Set the exit code
67
58
68
59
// Set the cause if provided in options
69
60
if ( options && options . cause ) {
@@ -74,15 +65,13 @@ class ErrorRPCHandlerFailed<T> extends ErrorRPC<T> {
74
65
75
66
class ErrorRPCMessageLength < T > extends ErrorRPC < T > {
76
67
static description = 'RPC Message exceeds maximum size' ;
77
- exitCode = sysexits . DATAERR ;
78
68
}
79
69
80
70
class ErrorRPCMissingResponse < T > extends ErrorRPC < T > {
81
71
constructor ( message ?: string ) {
82
72
super ( message ) ;
83
73
this . name = 'ErrorRPCMissingResponse' ;
84
74
this . description = 'Stream ended before response' ;
85
- this . exitCode = sysexits . UNAVAILABLE ;
86
75
}
87
76
}
88
77
@@ -97,7 +86,6 @@ class ErrorRPCOutputStreamError<T> extends ErrorRPC<T> {
97
86
super ( message ) ;
98
87
this . name = 'ErrorRPCOutputStreamError' ;
99
88
this . description = 'Output stream failed, unable to send data' ;
100
- this . exitCode = sysexits . UNAVAILABLE ;
101
89
102
90
// Set the cause if provided in options
103
91
if ( options && options . cause ) {
@@ -108,7 +96,6 @@ class ErrorRPCOutputStreamError<T> extends ErrorRPC<T> {
108
96
109
97
class ErrorRPCRemote < T > extends ErrorRPC < T > {
110
98
static description = 'Remote error from RPC call' ;
111
- exitCode : number = sysexits . UNAVAILABLE ;
112
99
metadata : JSONValue | undefined ;
113
100
114
101
constructor ( metadata ?: JSONValue , message ?: string , options ?) {
@@ -129,7 +116,6 @@ class ErrorRPCRemote<T> extends ErrorRPC<T> {
129
116
isNaN ( Date . parse ( json . data . timestamp ) ) ||
130
117
typeof json . data . metadata !== 'object' ||
131
118
typeof json . data . data !== 'object' ||
132
- typeof json . data . exitCode !== 'number' ||
133
119
( 'stack' in json . data && typeof json . data . stack !== 'string' )
134
120
) {
135
121
throw new TypeError ( `Cannot decode JSON to ${ this . name } ` ) ;
@@ -143,7 +129,6 @@ class ErrorRPCRemote<T> extends ErrorRPC<T> {
143
129
data : json . data . data ,
144
130
cause : json . data . cause ,
145
131
} ) ;
146
- e . exitCode = json . data . exitCode ;
147
132
e . stack = json . data . stack ;
148
133
return e ;
149
134
}
@@ -152,7 +137,6 @@ class ErrorRPCRemote<T> extends ErrorRPC<T> {
152
137
type : this . name ,
153
138
data : {
154
139
description : this . description ,
155
- exitCode : this . exitCode ,
156
140
} ,
157
141
} ;
158
142
}
@@ -163,7 +147,6 @@ class ErrorRPCStreamEnded<T> extends ErrorRPC<T> {
163
147
super ( message ) ;
164
148
this . name = 'ErrorRPCStreamEnded' ;
165
149
this . description = 'Handled stream has ended' ;
166
- this . exitCode = sysexits . NOINPUT ;
167
150
}
168
151
}
169
152
@@ -172,7 +155,6 @@ class ErrorRPCTimedOut<T> extends ErrorRPC<T> {
172
155
super ( message ) ;
173
156
this . name = 'ErrorRPCTimedOut' ;
174
157
this . description = 'RPC handler has timed out' ;
175
- this . exitCode = sysexits . UNAVAILABLE ;
176
158
}
177
159
}
178
160
@@ -181,7 +163,6 @@ class ErrorUtilsUndefinedBehaviour<T> extends ErrorRPC<T> {
181
163
super ( message ) ;
182
164
this . name = 'ErrorUtilsUndefinedBehaviour' ;
183
165
this . description = 'You should never see this error' ;
184
- this . exitCode = sysexits . SOFTWARE ;
185
166
}
186
167
}
187
168
export function never ( ) : never {
@@ -194,7 +175,6 @@ class ErrorRPCMethodNotImplemented<T> extends ErrorRPC<T> {
194
175
this . name = 'ErrorRPCMethodNotImplemented' ;
195
176
this . description =
196
177
'This abstract method must be implemented in a derived class' ;
197
- this . exitCode = sysexits . USAGE ; // Or another suitable exit code
198
178
}
199
179
}
200
180
0 commit comments