@@ -18,8 +18,147 @@ import { JournalEntry } from "../journal";
18
18
import { FailureWithTerminal } from "../generated/proto/javascript" ;
19
19
20
20
export enum ErrorCodes {
21
+ /**
22
+ * Not an error; returned on success.
23
+ * HTTP 200
24
+ */
25
+ OK = 0 ,
26
+ /**
27
+ * The operation was cancelled, typically by the caller.
28
+ * HTTP 408
29
+ */
30
+ CANCELLED = 1 ,
31
+ /**
32
+ * Unknown error. For example, this error may be returned when a
33
+ * Status value received from another address space belongs to an error
34
+ * space that is not known in this address space. Also errors raised by APIs
35
+ * that do not return enough error information may be converted to this
36
+ * error.
37
+ * HTTP 500
38
+ */
21
39
UNKNOWN = 2 ,
40
+ /**
41
+ * The client specified an invalid argument. Note that
42
+ * this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates
43
+ * arguments that are problematic regardless of the state of the system
44
+ * (e.g., a malformed file name).
45
+ * HTTP 400
46
+ */
47
+ INVALID_ARGUMENT = 3 ,
48
+ /**
49
+ * The deadline expired before the operation could
50
+ * complete. For operations that change the state of the system, this error
51
+ * may be returned even if the operation has completed successfully. For
52
+ * example, a successful response from a server could have been delayed
53
+ * long.
54
+ * HTTP 408
55
+ */
56
+ DEADLINE_EXCEEDED = 4 ,
57
+ /**
58
+ * Some requested entity (e.g., file or directory) was not
59
+ * found. Note to server developers: if a request is denied for an entire
60
+ * class of users, such as gradual feature rollout or undocumented
61
+ * allowlist, NOT_FOUND may be used. If a request is denied for some users
62
+ * within a class of users, such as user-based access control,
63
+ * PERMISSION_DENIED must be used.
64
+ * HTTP 404
65
+ */
66
+ NOT_FOUND = 5 ,
67
+ /**
68
+ * The entity that a client attempted to create (e.g., file
69
+ * or directory) already exists.
70
+ * HTTP 409
71
+ */
72
+ ALREADY_EXISTS = 6 ,
73
+ /**
74
+ * The caller does not have permission to execute the
75
+ * specified operation. PERMISSION_DENIED must not be used for rejections
76
+ * caused by exhausting some resource (use RESOURCE_EXHAUSTED instead for
77
+ * those errors). PERMISSION_DENIED must not be used if the caller can not
78
+ * be identified (use UNAUTHENTICATED instead for those errors). This error
79
+ * code does not imply the request is valid or the requested entity exists
80
+ * or satisfies other pre-conditions.
81
+ * HTTP 403
82
+ */
83
+ PERMISSION_DENIED = 7 ,
84
+ /**
85
+ * Some resource has been exhausted, perhaps a per-user
86
+ * quota, or perhaps the entire file system is out of space.
87
+ * HTTP 413
88
+ */
89
+ RESOURCE_EXHAUSTED = 8 ,
90
+ /**
91
+ * The operation was rejected because the system is
92
+ * not in a state required for the operation's execution. For example, the
93
+ * directory to be deleted is non-empty, an rmdir operation is applied to a
94
+ * non-directory, etc. Service implementors can use the following guidelines
95
+ * to decide between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use
96
+ * UNAVAILABLE if the client can retry just the failing call. (b) Use
97
+ * ABORTED if the client should retry at a higher level (e.g., when a
98
+ * client-specified test-and-set fails, indicating the client should restart
99
+ * a read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client
100
+ * should not retry until the system state has been explicitly fixed. E.g.,
101
+ * if an "rmdir" fails because the directory is non-empty,
102
+ * FAILED_PRECONDITION should be returned since the client should not retry
103
+ * unless the files are deleted from the directory.
104
+ * HTTP 412
105
+ */
106
+ FAILED_PRECONDITION = 9 ,
107
+ /**
108
+ * The operation was aborted, typically due to a concurrency issue
109
+ * such as a sequencer check failure or transaction abort. See the
110
+ * guidelines above for deciding between FAILED_PRECONDITION, ABORTED, and
111
+ * UNAVAILABLE.
112
+ * HTTP 409
113
+ */
114
+ ABORTED = 10 ,
115
+ /**
116
+ * The operation was attempted past the valid range. E.g.,
117
+ * seeking or reading past end-of-file. Unlike INVALID_ARGUMENT, this error
118
+ * indicates a problem that may be fixed if the system state changes. For
119
+ * example, a 32-bit file system will generate INVALID_ARGUMENT if asked to
120
+ * read at an offset that is not in the range [0,2^32-1], but it will
121
+ * generate OUT_OF_RANGE if asked to read from an offset past the current
122
+ * file size. There is a fair bit of overlap between FAILED_PRECONDITION and
123
+ * OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
124
+ * when it applies so that callers who are iterating through a space can
125
+ * easily look for an OUT_OF_RANGE error to detect when they are done.
126
+ * HTTP 400
127
+ */
128
+ OUT_OF_RANGE = 11 ,
129
+ /**
130
+ * The operation is not implemented or is not
131
+ * supported/enabled in this service.
132
+ * HTTP 501
133
+ */
134
+ UNIMPLEMENTED = 12 ,
135
+ /**
136
+ * Internal errors. This means that some invariants expected by
137
+ * the underlying system have been broken. This error code is reserved for
138
+ * serious errors.
139
+ * HTTP 500
140
+ */
22
141
INTERNAL = 13 ,
142
+ /**
143
+ * The service is currently unavailable. This is most likely a
144
+ * transient condition, which can be corrected by retrying with a backoff.
145
+ * Note that it is not always safe to retry non-idempotent operations.
146
+ * HTTP 503
147
+ */
148
+ UNAVAILABLE = 14 ,
149
+ /**
150
+ * Unrecoverable data loss or corruption.
151
+ * HTTP 500
152
+ */
153
+ DATA_LOSS = 15 ,
154
+ /**
155
+ * The request does not have valid authentication
156
+ * credentials for the operation.
157
+ * HTTP 401
158
+ */
159
+ UNAUTHENTICATED = 16 ,
160
+ }
161
+ export enum RestateErrorCodes {
23
162
JOURNAL_MISMATCH = 32 ,
24
163
PROTOCOL_VIOLATION = 33 ,
25
164
}
@@ -86,12 +225,12 @@ export class RetryableError extends RestateError {
86
225
- In the replayed messages: type: ${
87
226
replayMessage . messageType
88
227
} , message: ${ printMessageAsJson ( replayMessage . message ) } `;
89
- return new RetryableError ( msg , { errorCode : ErrorCodes . JOURNAL_MISMATCH } ) ;
228
+ return new RetryableError ( msg , { errorCode : RestateErrorCodes . JOURNAL_MISMATCH } ) ;
90
229
}
91
230
92
231
public static protocolViolation ( message : string ) {
93
232
return new RetryableError ( message , {
94
- errorCode : ErrorCodes . PROTOCOL_VIOLATION ,
233
+ errorCode : RestateErrorCodes . PROTOCOL_VIOLATION ,
95
234
} ) ;
96
235
}
97
236
0 commit comments