@powersync/service-errors 0.0.0-dev-20250122110924

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ # Functional Source License, Version 1.1, Apache 2.0 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2023-2024 Journey Mobile, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
20
+
21
+ ### License Grant
22
+
23
+ Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
24
+
25
+ ### Permitted Purpose
26
+
27
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
28
+
29
+ 1. substitutes for the Software;
30
+ 2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
31
+ 3. offers the same or substantially similar functionality as the Software.
32
+
33
+ Permitted Purposes specifically include using the Software:
34
+
35
+ 1. for your internal use and access;
36
+ 2. for non-commercial education;
37
+ 3. for non-commercial research; and
38
+ 4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
39
+
40
+ ### Patents
41
+
42
+ To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
43
+
44
+ ### Redistribution
45
+
46
+ The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
47
+ If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
48
+
49
+ ### Disclaimer
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
52
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
53
+
54
+ ### Trademarks
55
+
56
+ Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
57
+
58
+ ## Grant of Future License
59
+
60
+ We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
61
+
62
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
63
+ You may obtain a copy of the License at
64
+
65
+ http://www.apache.org/licenses/LICENSE-2.0
66
+
67
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @powersync/service-errors
2
+
3
+ Defines error codes used across the service.
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Error codes used across the service.
3
+ *
4
+ * This is the primary definition of error codes, as well as the documentation
5
+ * for each.
6
+ */
7
+ export declare enum ErrorCode {
8
+ /**
9
+ * Catch-all sync rules parsing error, if no more specific error is available
10
+ */
11
+ PSYNC_R0001 = "PSYNC_R0001",
12
+ /**
13
+ * Internal assertion.
14
+ *
15
+ * If you see this error, it might indicate a bug in the service code.
16
+ */
17
+ PSYNC_S0001 = "PSYNC_S0001",
18
+ /**
19
+ * TEARDOWN was not acknowledged.
20
+ *
21
+ * This happens when the TEARDOWN argument was not supplied when running
22
+ * the service teardown command. The TEARDOWN argument is required since
23
+ * this is a destructive command.
24
+ *
25
+ * Run the command with `teardown TEARDOWN` to confirm.
26
+ */
27
+ PSYNC_S0102 = "PSYNC_S0102",
28
+ /**
29
+ * Row too large.
30
+ *
31
+ * There is a 15MB size limit on every replicated row - rows larger than
32
+ * this cannot be replicated.
33
+ */
34
+ PSYNC_S1002 = "PSYNC_S1002",
35
+ /**
36
+ * Sync rules have been locked by another process for replication.
37
+ *
38
+ * This error is normal in some circumstances:
39
+ * 1. In some cases, if a process was forcefully terminated, this error may occur for up to a minute.
40
+ * 2. During rolling deploys, this error may occur until the old process stops replication.
41
+ *
42
+ * If the error persists for longer, this may indicate that multiple replication processes are running.
43
+ * Make sure there is only one replication process apart from rolling deploys.
44
+ */
45
+ PSYNC_S1003 = "PSYNC_S1003",
46
+ /**
47
+ * JSON nested object depth exceeds the limit of 20.
48
+ *
49
+ * This may occur if there is very deep nesting in JSON or embedded documents.
50
+ */
51
+ PSYNC_S1004 = "PSYNC_S1004",
52
+ /**
53
+ * Replication assertion error.
54
+ *
55
+ * If you see this error, it might indicate a bug in the service code.
56
+ */
57
+ PSYNC_S1101 = "PSYNC_S1101",
58
+ /**
59
+ * Aborted initial replication.
60
+ *
61
+ * This is not an actual error - it is expected when the replication process
62
+ * is stopped, or if replication is stopped for any other reason.
63
+ */
64
+ PSYNC_S1103 = "PSYNC_S1103",
65
+ /**
66
+ * Explicit cacert is required for `sslmode: verify-ca`.
67
+ *
68
+ * Use either verify-full, or specify a certificate with verify-ca.
69
+ */
70
+ PSYNC_S1104 = "PSYNC_S1104",
71
+ /**
72
+ * `database` is required in connection config.
73
+ *
74
+ * Specify the database explicitly, or in the `uri` field.
75
+ */
76
+ PSYNC_S1105 = "PSYNC_S1105",
77
+ /**
78
+ * `hostname` is required in connection config.
79
+ *
80
+ * Specify the hostname explicitly, or in the `uri` field.
81
+ */
82
+ PSYNC_S1106 = "PSYNC_S1106",
83
+ /**
84
+ * `username` is required in connection config.
85
+ *
86
+ * Specify the username explicitly, or in the `uri` field.
87
+ */
88
+ PSYNC_S1107 = "PSYNC_S1107",
89
+ /**
90
+ * `password` is required in connection config.
91
+ *
92
+ * Specify the password explicitly, or in the `uri` field.
93
+ */
94
+ PSYNC_S1108 = "PSYNC_S1108",
95
+ /**
96
+ * Invalid database URI.
97
+ *
98
+ * Check the URI scheme and format.
99
+ */
100
+ PSYNC_S1109 = "PSYNC_S1109",
101
+ /**
102
+ * Invalid port number.
103
+ *
104
+ * Only ports in the range 1024 - 65535 are supported.
105
+ */
106
+ PSYNC_S1110 = "PSYNC_S1110",
107
+ /**
108
+ * Publication does not exist.
109
+ *
110
+ * Run: `CREATE PUBLICATION powersync FOR ALL TABLES` on the source database.
111
+ */
112
+ PSYNC_S1141 = "PSYNC_S1141",
113
+ /**
114
+ * Publication does not publish all changes.
115
+ *
116
+ * Create a publication using `WITH (publish = "insert, update, delete, truncate")` (the default).
117
+ */
118
+ PSYNC_S1142 = "PSYNC_S1142",
119
+ /**
120
+ * Publication uses publish_via_partition_root.
121
+ */
122
+ PSYNC_S1143 = "PSYNC_S1143",
123
+ /**
124
+ * Generic MongoServerError.
125
+ */
126
+ PSYNC_S1301 = "PSYNC_S1301",
127
+ /**
128
+ * Generic MongoNetworkError.
129
+ */
130
+ PSYNC_S1302 = "PSYNC_S1302",
131
+ /**
132
+ * MongoDB internal TLS error.
133
+ *
134
+ * If connection to a shared cluster on MongoDB Atlas, this could be an IP Acccess List issue.
135
+ * Check that the service IP is allowed to connect to the cluster.
136
+ */
137
+ PSYNC_S1303 = "PSYNC_S1303",
138
+ /**
139
+ * MongoDB connection DNS error.
140
+ *
141
+ * Check that the hostname is correct.
142
+ */
143
+ PSYNC_S1304 = "PSYNC_S1304",
144
+ /**
145
+ * MongoDB connection timeout.
146
+ *
147
+ * Check that the hostname is correct, and that the service IP is allowed to connect to the cluster.
148
+ */
149
+ PSYNC_S1305 = "PSYNC_S1305",
150
+ /**
151
+ * MongoDB authentication error.
152
+ *
153
+ * Check the username and password.
154
+ */
155
+ PSYNC_S1306 = "PSYNC_S1306",
156
+ /**
157
+ * MongoDB authorization error.
158
+ *
159
+ * Check that the user has the required priviledges.
160
+ */
161
+ PSYNC_S1307 = "PSYNC_S1307",
162
+ /**
163
+ * Sharded MongoDB Clusters are not supported yet.
164
+ */
165
+ PSYNC_S1341 = "PSYNC_S1341",
166
+ /**
167
+ * Standalone MongoDB instances are not supported - use a replicaset.
168
+ */
169
+ PSYNC_S1342 = "PSYNC_S1342",
170
+ /**
171
+ * PostImages not enabled on a source collection.
172
+ *
173
+ * Use `post_images: auto_configure` to configure post images automatically, or enable manually:
174
+ *
175
+ * db.runCommand({
176
+ * collMod: 'collection-name',
177
+ * changeStreamPreAndPostImages: { enabled: true }
178
+ * });
179
+ */
180
+ PSYNC_S1343 = "PSYNC_S1343",
181
+ /**
182
+ * Max transaction tries exceeded.
183
+ */
184
+ PSYNC_S1402 = "PSYNC_S1402",
185
+ /**
186
+ * Generic internal server error (HTTP 500).
187
+ *
188
+ * See the error details for more info.
189
+ */
190
+ PSYNC_S2001 = "PSYNC_S2001",
191
+ /**
192
+ * Route not found (HTTP 404).
193
+ */
194
+ PSYNC_S2002 = "PSYNC_S2002",
195
+ /**
196
+ * 503 service unavailable due to restart.
197
+ *
198
+ * Wait a while then retry the request.
199
+ */
200
+ PSYNC_S2003 = "PSYNC_S2003",
201
+ /**
202
+ * Generic authentication error.
203
+ */
204
+ PSYNC_S2101 = "PSYNC_S2101",
205
+ /**
206
+ * IPv6 support is not enabled for the JWKS URI.
207
+ *
208
+ * Use an endpoint that supports IPv4.
209
+ */
210
+ PSYNC_S2202 = "PSYNC_S2202",
211
+ /**
212
+ * IPs in this range are not supported.
213
+ *
214
+ * Make sure to use a publically-accessible JWKS URI.
215
+ */
216
+ PSYNC_S2203 = "PSYNC_S2203",
217
+ /**
218
+ * No sync rules available.
219
+ *
220
+ * This error may happen if:
221
+ * 1. Sync rules have not been deployed.
222
+ * 2. Sync rules have been deployed, but is still busy processing.
223
+ *
224
+ * View the replicator logs to see if the sync rules are being processed.
225
+ */
226
+ PSYNC_S2302 = "PSYNC_S2302",
227
+ /**
228
+ * Maximum active concurrent connections limit has been reached.
229
+ */
230
+ PSYNC_S2304 = "PSYNC_S2304",
231
+ /**
232
+ * Could not get clusterTime.
233
+ */
234
+ PSYNC_S2401 = "PSYNC_S2401",
235
+ /**
236
+ * Invalid jwks_uri.
237
+ */
238
+ PSYNC_S3102 = "PSYNC_S3102",
239
+ /**
240
+ * Only http(s) is supported for jwks_uri.
241
+ */
242
+ PSYNC_S3103 = "PSYNC_S3103",
243
+ /**
244
+ * Failed to validate module configuration.
245
+ */
246
+ PSYNC_S3201 = "PSYNC_S3201",
247
+ /**
248
+ * Internal assertion error.
249
+ *
250
+ * This error may indicate a bug in the service code.
251
+ */
252
+ PSYNC_S4001 = "PSYNC_S4001",
253
+ /**
254
+ * No active sync rules.
255
+ */
256
+ PSYNC_S4104 = "PSYNC_S4104",
257
+ /**
258
+ * Sync rules API disabled.
259
+ *
260
+ * When a sync rules file is configured, the dynamic sync rules API is disabled.
261
+ */
262
+ PSYNC_S4105 = "PSYNC_S4105"
263
+ }
package/dist/codes.js ADDED
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Error codes used across the service.
3
+ *
4
+ * This is the primary definition of error codes, as well as the documentation
5
+ * for each.
6
+ */
7
+ export var ErrorCode;
8
+ (function (ErrorCode) {
9
+ // # PSYNC_Rxxxx: Sync rules issues
10
+ /**
11
+ * Catch-all sync rules parsing error, if no more specific error is available
12
+ */
13
+ ErrorCode["PSYNC_R0001"] = "PSYNC_R0001";
14
+ // ## PSYNC_R11xx: YAML syntax issues
15
+ // ## PSYNC_R12xx: YAML structure (schema) issues
16
+ // ## PSYNC_R21xx: SQL syntax issues
17
+ // ## PSYNC_R22xx: SQL supported feature issues
18
+ // ## PSYNC_R23xx: SQL schema mismatch issues
19
+ // ## PSYNC_R24xx: SQL security warnings
20
+ // # PSYNC_Sxxxx: Service issues
21
+ /**
22
+ * Internal assertion.
23
+ *
24
+ * If you see this error, it might indicate a bug in the service code.
25
+ */
26
+ ErrorCode["PSYNC_S0001"] = "PSYNC_S0001";
27
+ /**
28
+ * TEARDOWN was not acknowledged.
29
+ *
30
+ * This happens when the TEARDOWN argument was not supplied when running
31
+ * the service teardown command. The TEARDOWN argument is required since
32
+ * this is a destructive command.
33
+ *
34
+ * Run the command with `teardown TEARDOWN` to confirm.
35
+ */
36
+ ErrorCode["PSYNC_S0102"] = "PSYNC_S0102";
37
+ // ## PSYNC_S1xxx: Replication issues
38
+ /**
39
+ * Row too large.
40
+ *
41
+ * There is a 15MB size limit on every replicated row - rows larger than
42
+ * this cannot be replicated.
43
+ */
44
+ ErrorCode["PSYNC_S1002"] = "PSYNC_S1002";
45
+ /**
46
+ * Sync rules have been locked by another process for replication.
47
+ *
48
+ * This error is normal in some circumstances:
49
+ * 1. In some cases, if a process was forcefully terminated, this error may occur for up to a minute.
50
+ * 2. During rolling deploys, this error may occur until the old process stops replication.
51
+ *
52
+ * If the error persists for longer, this may indicate that multiple replication processes are running.
53
+ * Make sure there is only one replication process apart from rolling deploys.
54
+ */
55
+ ErrorCode["PSYNC_S1003"] = "PSYNC_S1003";
56
+ /**
57
+ * JSON nested object depth exceeds the limit of 20.
58
+ *
59
+ * This may occur if there is very deep nesting in JSON or embedded documents.
60
+ */
61
+ ErrorCode["PSYNC_S1004"] = "PSYNC_S1004";
62
+ // ## PSYNC_S11xx: Postgres replication issues
63
+ /**
64
+ * Replication assertion error.
65
+ *
66
+ * If you see this error, it might indicate a bug in the service code.
67
+ */
68
+ ErrorCode["PSYNC_S1101"] = "PSYNC_S1101";
69
+ /**
70
+ * Aborted initial replication.
71
+ *
72
+ * This is not an actual error - it is expected when the replication process
73
+ * is stopped, or if replication is stopped for any other reason.
74
+ */
75
+ ErrorCode["PSYNC_S1103"] = "PSYNC_S1103";
76
+ /**
77
+ * Explicit cacert is required for `sslmode: verify-ca`.
78
+ *
79
+ * Use either verify-full, or specify a certificate with verify-ca.
80
+ */
81
+ ErrorCode["PSYNC_S1104"] = "PSYNC_S1104";
82
+ /**
83
+ * `database` is required in connection config.
84
+ *
85
+ * Specify the database explicitly, or in the `uri` field.
86
+ */
87
+ ErrorCode["PSYNC_S1105"] = "PSYNC_S1105";
88
+ /**
89
+ * `hostname` is required in connection config.
90
+ *
91
+ * Specify the hostname explicitly, or in the `uri` field.
92
+ */
93
+ ErrorCode["PSYNC_S1106"] = "PSYNC_S1106";
94
+ /**
95
+ * `username` is required in connection config.
96
+ *
97
+ * Specify the username explicitly, or in the `uri` field.
98
+ */
99
+ ErrorCode["PSYNC_S1107"] = "PSYNC_S1107";
100
+ /**
101
+ * `password` is required in connection config.
102
+ *
103
+ * Specify the password explicitly, or in the `uri` field.
104
+ */
105
+ ErrorCode["PSYNC_S1108"] = "PSYNC_S1108";
106
+ /**
107
+ * Invalid database URI.
108
+ *
109
+ * Check the URI scheme and format.
110
+ */
111
+ ErrorCode["PSYNC_S1109"] = "PSYNC_S1109";
112
+ /**
113
+ * Invalid port number.
114
+ *
115
+ * Only ports in the range 1024 - 65535 are supported.
116
+ */
117
+ ErrorCode["PSYNC_S1110"] = "PSYNC_S1110";
118
+ /**
119
+ * Publication does not exist.
120
+ *
121
+ * Run: `CREATE PUBLICATION powersync FOR ALL TABLES` on the source database.
122
+ */
123
+ ErrorCode["PSYNC_S1141"] = "PSYNC_S1141";
124
+ /**
125
+ * Publication does not publish all changes.
126
+ *
127
+ * Create a publication using `WITH (publish = "insert, update, delete, truncate")` (the default).
128
+ */
129
+ ErrorCode["PSYNC_S1142"] = "PSYNC_S1142";
130
+ /**
131
+ * Publication uses publish_via_partition_root.
132
+ */
133
+ ErrorCode["PSYNC_S1143"] = "PSYNC_S1143";
134
+ // ## PSYNC_S12xx: MySQL replication issues
135
+ // ## PSYNC_S13xx: MongoDB replication issues
136
+ /**
137
+ * Generic MongoServerError.
138
+ */
139
+ ErrorCode["PSYNC_S1301"] = "PSYNC_S1301";
140
+ /**
141
+ * Generic MongoNetworkError.
142
+ */
143
+ ErrorCode["PSYNC_S1302"] = "PSYNC_S1302";
144
+ /**
145
+ * MongoDB internal TLS error.
146
+ *
147
+ * If connection to a shared cluster on MongoDB Atlas, this could be an IP Acccess List issue.
148
+ * Check that the service IP is allowed to connect to the cluster.
149
+ */
150
+ ErrorCode["PSYNC_S1303"] = "PSYNC_S1303";
151
+ /**
152
+ * MongoDB connection DNS error.
153
+ *
154
+ * Check that the hostname is correct.
155
+ */
156
+ ErrorCode["PSYNC_S1304"] = "PSYNC_S1304";
157
+ /**
158
+ * MongoDB connection timeout.
159
+ *
160
+ * Check that the hostname is correct, and that the service IP is allowed to connect to the cluster.
161
+ */
162
+ ErrorCode["PSYNC_S1305"] = "PSYNC_S1305";
163
+ /**
164
+ * MongoDB authentication error.
165
+ *
166
+ * Check the username and password.
167
+ */
168
+ ErrorCode["PSYNC_S1306"] = "PSYNC_S1306";
169
+ /**
170
+ * MongoDB authorization error.
171
+ *
172
+ * Check that the user has the required priviledges.
173
+ */
174
+ ErrorCode["PSYNC_S1307"] = "PSYNC_S1307";
175
+ /**
176
+ * Sharded MongoDB Clusters are not supported yet.
177
+ */
178
+ ErrorCode["PSYNC_S1341"] = "PSYNC_S1341";
179
+ /**
180
+ * Standalone MongoDB instances are not supported - use a replicaset.
181
+ */
182
+ ErrorCode["PSYNC_S1342"] = "PSYNC_S1342";
183
+ /**
184
+ * PostImages not enabled on a source collection.
185
+ *
186
+ * Use `post_images: auto_configure` to configure post images automatically, or enable manually:
187
+ *
188
+ * db.runCommand({
189
+ * collMod: 'collection-name',
190
+ * changeStreamPreAndPostImages: { enabled: true }
191
+ * });
192
+ */
193
+ ErrorCode["PSYNC_S1343"] = "PSYNC_S1343";
194
+ // ## PSYNC_S14xx: MongoDB storage replication issues
195
+ /**
196
+ * Max transaction tries exceeded.
197
+ */
198
+ ErrorCode["PSYNC_S1402"] = "PSYNC_S1402";
199
+ // ## PSYNC_S2xxx: Service API
200
+ /**
201
+ * Generic internal server error (HTTP 500).
202
+ *
203
+ * See the error details for more info.
204
+ */
205
+ ErrorCode["PSYNC_S2001"] = "PSYNC_S2001";
206
+ /**
207
+ * Route not found (HTTP 404).
208
+ */
209
+ ErrorCode["PSYNC_S2002"] = "PSYNC_S2002";
210
+ /**
211
+ * 503 service unavailable due to restart.
212
+ *
213
+ * Wait a while then retry the request.
214
+ */
215
+ ErrorCode["PSYNC_S2003"] = "PSYNC_S2003";
216
+ // ## PSYNC_S21xx: Auth errors originating on the client.
217
+ //
218
+ // This does not include auth configuration errors on the service.
219
+ /**
220
+ * Generic authentication error.
221
+ */
222
+ ErrorCode["PSYNC_S2101"] = "PSYNC_S2101";
223
+ // ## PSYNC_S22xx: Auth integration errors
224
+ /**
225
+ * IPv6 support is not enabled for the JWKS URI.
226
+ *
227
+ * Use an endpoint that supports IPv4.
228
+ */
229
+ ErrorCode["PSYNC_S2202"] = "PSYNC_S2202";
230
+ /**
231
+ * IPs in this range are not supported.
232
+ *
233
+ * Make sure to use a publically-accessible JWKS URI.
234
+ */
235
+ ErrorCode["PSYNC_S2203"] = "PSYNC_S2203";
236
+ // ## PSYNC_S23xx: Sync API errors
237
+ /**
238
+ * No sync rules available.
239
+ *
240
+ * This error may happen if:
241
+ * 1. Sync rules have not been deployed.
242
+ * 2. Sync rules have been deployed, but is still busy processing.
243
+ *
244
+ * View the replicator logs to see if the sync rules are being processed.
245
+ */
246
+ ErrorCode["PSYNC_S2302"] = "PSYNC_S2302";
247
+ /**
248
+ * Maximum active concurrent connections limit has been reached.
249
+ */
250
+ ErrorCode["PSYNC_S2304"] = "PSYNC_S2304";
251
+ // ## PSYNC_S23xx: Sync API errors - MongoDB Storage
252
+ /**
253
+ * Could not get clusterTime.
254
+ */
255
+ ErrorCode["PSYNC_S2401"] = "PSYNC_S2401";
256
+ // ## PSYNC_S23xx: Sync API errors - Postgres Storage
257
+ // ## PSYNC_S3xxx: Service configuration issues
258
+ // ## PSYNC_S31xx: Auth configuration issues
259
+ /**
260
+ * Invalid jwks_uri.
261
+ */
262
+ ErrorCode["PSYNC_S3102"] = "PSYNC_S3102";
263
+ /**
264
+ * Only http(s) is supported for jwks_uri.
265
+ */
266
+ ErrorCode["PSYNC_S3103"] = "PSYNC_S3103";
267
+ // ## PSYNC_S32xx: Replication configuration issue.
268
+ /**
269
+ * Failed to validate module configuration.
270
+ */
271
+ ErrorCode["PSYNC_S3201"] = "PSYNC_S3201";
272
+ // ## PSYNC_S4000: management / dev apis
273
+ /**
274
+ * Internal assertion error.
275
+ *
276
+ * This error may indicate a bug in the service code.
277
+ */
278
+ ErrorCode["PSYNC_S4001"] = "PSYNC_S4001";
279
+ /**
280
+ * No active sync rules.
281
+ */
282
+ ErrorCode["PSYNC_S4104"] = "PSYNC_S4104";
283
+ /**
284
+ * Sync rules API disabled.
285
+ *
286
+ * When a sync rules file is configured, the dynamic sync rules API is disabled.
287
+ */
288
+ ErrorCode["PSYNC_S4105"] = "PSYNC_S4105";
289
+ })(ErrorCode || (ErrorCode = {}));
290
+ //# sourceMappingURL=codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codes.js","sourceRoot":"","sources":["../src/codes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAN,IAAY,SA2VX;AA3VD,WAAY,SAAS;IACnB,mCAAmC;IAEnC;;OAEG;IACH,wCAA2B,CAAA;IAE3B,qCAAqC;IAErC,iDAAiD;IAEjD,oCAAoC;IAEpC,+CAA+C;IAE/C,6CAA6C;IAE7C,wCAAwC;IAExC,gCAAgC;IAEhC;;;;OAIG;IACH,wCAA2B,CAAA;IAE3B;;;;;;;;OAQG;IACH,wCAA2B,CAAA;IAE3B,qCAAqC;IAErC;;;;;OAKG;IACH,wCAA2B,CAAA;IAE3B;;;;;;;;;OASG;IACH,wCAA2B,CAA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;;;OAQG;IACH,wCAA2B,CAAA;IAE3B;;OAEG;IACH,wCAA2B,CAAA;IAE3B,oDAAoD;IAEpD;;OAEG;IACH,wCAA2B,CAAA;IAE3B,qDAAqD;IAErD,+CAA+C;IAE/C,4CAA4C;IAE5C;;OAEG;IACH,wCAA2B,CAAA;IAE3B;;OAEG;IACH,wCAA2B,CAAA;IAE3B,mDAAmD;IAEnD;;OAEG;IACH,wCAA2B,CAAA;IAE3B,wCAAwC;IAExC;;;;OAIG;IACH,wCAA2B,CAAA;IAE3B;;OAEG;IACH,wCAA2B,CAAA;IAE3B;;;;OAIG;IACH,wCAA2B,CAAA;AAC7B,CAAC,EA3VW,SAAS,KAAT,SAAS,QA2VpB"}
@@ -0,0 +1,83 @@
1
+ import { ErrorCode } from './codes.js';
2
+ export declare enum ErrorSeverity {
3
+ INFO = "info",
4
+ WARNING = "warning",
5
+ ERROR = "error"
6
+ }
7
+ export type ErrorData = {
8
+ name?: string;
9
+ code: ErrorCode;
10
+ description: string;
11
+ severity?: ErrorSeverity;
12
+ details?: string;
13
+ status?: number;
14
+ stack?: string;
15
+ origin?: string;
16
+ trace_id?: string;
17
+ };
18
+ export declare class ServiceError extends Error {
19
+ is_service_error: boolean;
20
+ errorData: ErrorData;
21
+ static isServiceError(input: any): input is ServiceError;
22
+ private static errorMessage;
23
+ constructor(data: ErrorData);
24
+ constructor(code: ErrorCode, description: string);
25
+ toString(): string | undefined;
26
+ toJSON(): ErrorData;
27
+ setTraceId(id: string): void;
28
+ }
29
+ /**
30
+ * @deprecated Use more specific errors
31
+ */
32
+ export declare class ValidationError extends ServiceError {
33
+ static readonly CODE = ErrorCode.PSYNC_S2001;
34
+ constructor(errors: any);
35
+ }
36
+ /**
37
+ * Use for replication errors that are never expected to happen in production.
38
+ *
39
+ * If it does happen, it is either:
40
+ * 1. A bug in the code that should be fixed.
41
+ * 2. An error that needs a different error code.
42
+ */
43
+ export declare class ReplicationAssertionError extends ServiceError {
44
+ static readonly CODE = ErrorCode.PSYNC_S1101;
45
+ constructor(description: string);
46
+ }
47
+ /**
48
+ * Use for general service errors that are never expected to happen in production.
49
+ *
50
+ * If it does happen, it is either:
51
+ * 1. A bug in the code that should be fixed.
52
+ * 2. An error that needs a different error code.
53
+ */
54
+ export declare class ServiceAssertionError extends ServiceError {
55
+ static readonly CODE = ErrorCode.PSYNC_S0001;
56
+ constructor(description: string);
57
+ }
58
+ /**
59
+ * Indicates replication is aborted.
60
+ *
61
+ * This is not an actual error - rather just an indication
62
+ * that something requested the replication should stop.
63
+ */
64
+ export declare class ReplicationAbortedError extends ServiceError {
65
+ static readonly CODE = ErrorCode.PSYNC_S1103;
66
+ constructor(description?: string);
67
+ }
68
+ export declare class AuthorizationError extends ServiceError {
69
+ static readonly CODE = ErrorCode.PSYNC_S2101;
70
+ constructor(errors: any);
71
+ }
72
+ export declare class InternalServerError extends ServiceError {
73
+ static readonly CODE = ErrorCode.PSYNC_S2001;
74
+ constructor(err: Error);
75
+ }
76
+ export declare class RouteNotFound extends ServiceError {
77
+ static readonly CODE = ErrorCode.PSYNC_S2002;
78
+ constructor(path: string);
79
+ }
80
+ export declare class DatabaseConnectionError extends ServiceError {
81
+ cause: any;
82
+ constructor(code: ErrorCode, message: string, cause: any);
83
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,174 @@
1
+ import { ErrorCode } from './codes.js';
2
+ export var ErrorSeverity;
3
+ (function (ErrorSeverity) {
4
+ ErrorSeverity["INFO"] = "info";
5
+ ErrorSeverity["WARNING"] = "warning";
6
+ ErrorSeverity["ERROR"] = "error";
7
+ })(ErrorSeverity || (ErrorSeverity = {}));
8
+ export class ServiceError extends Error {
9
+ static isServiceError(input) {
10
+ return input instanceof ServiceError || input?.is_service_error == true;
11
+ }
12
+ static errorMessage(data, description) {
13
+ if (typeof data == 'string') {
14
+ data = {
15
+ code: data,
16
+ description: description
17
+ };
18
+ }
19
+ let message = `[${data.code}] ${data.description}`;
20
+ if (data.details) {
21
+ message += `\n ${data.details}`;
22
+ }
23
+ return message;
24
+ }
25
+ constructor(data, description) {
26
+ super(ServiceError.errorMessage(data, description));
27
+ this.is_service_error = true;
28
+ if (typeof data == 'string') {
29
+ data = {
30
+ code: data,
31
+ description: description
32
+ };
33
+ }
34
+ this.errorData = data;
35
+ if (data.stack) {
36
+ this.stack = data.stack;
37
+ }
38
+ this.name = data.name || this.constructor.name;
39
+ this.errorData.name = this.name;
40
+ }
41
+ toString() {
42
+ return this.stack;
43
+ }
44
+ toJSON() {
45
+ if (process.env.NODE_ENV !== 'production') {
46
+ return this.errorData;
47
+ }
48
+ return {
49
+ name: this.errorData.name,
50
+ code: this.errorData.code,
51
+ status: this.errorData.status,
52
+ description: this.errorData.description,
53
+ details: this.errorData.details,
54
+ trace_id: this.errorData.trace_id,
55
+ severity: this.errorData.severity,
56
+ origin: this.errorData.origin
57
+ };
58
+ }
59
+ setTraceId(id) {
60
+ this.errorData.trace_id = id;
61
+ }
62
+ }
63
+ /**
64
+ * @deprecated Use more specific errors
65
+ */
66
+ export class ValidationError extends ServiceError {
67
+ constructor(errors) {
68
+ super({
69
+ code: ValidationError.CODE,
70
+ status: 400,
71
+ description: 'Validation failed',
72
+ details: JSON.stringify(errors)
73
+ });
74
+ }
75
+ }
76
+ ValidationError.CODE = ErrorCode.PSYNC_S2001;
77
+ /**
78
+ * Use for replication errors that are never expected to happen in production.
79
+ *
80
+ * If it does happen, it is either:
81
+ * 1. A bug in the code that should be fixed.
82
+ * 2. An error that needs a different error code.
83
+ */
84
+ export class ReplicationAssertionError extends ServiceError {
85
+ constructor(description) {
86
+ super({
87
+ code: ReplicationAssertionError.CODE,
88
+ status: 500,
89
+ description: description
90
+ });
91
+ }
92
+ }
93
+ ReplicationAssertionError.CODE = ErrorCode.PSYNC_S1101;
94
+ /**
95
+ * Use for general service errors that are never expected to happen in production.
96
+ *
97
+ * If it does happen, it is either:
98
+ * 1. A bug in the code that should be fixed.
99
+ * 2. An error that needs a different error code.
100
+ */
101
+ export class ServiceAssertionError extends ServiceError {
102
+ constructor(description) {
103
+ super({
104
+ code: ServiceAssertionError.CODE,
105
+ status: 500,
106
+ description: description
107
+ });
108
+ }
109
+ }
110
+ ServiceAssertionError.CODE = ErrorCode.PSYNC_S0001;
111
+ /**
112
+ * Indicates replication is aborted.
113
+ *
114
+ * This is not an actual error - rather just an indication
115
+ * that something requested the replication should stop.
116
+ */
117
+ export class ReplicationAbortedError extends ServiceError {
118
+ constructor(description) {
119
+ super({
120
+ code: ReplicationAbortedError.CODE,
121
+ description: description ?? 'Replication aborted'
122
+ });
123
+ }
124
+ }
125
+ ReplicationAbortedError.CODE = ErrorCode.PSYNC_S1103;
126
+ export class AuthorizationError extends ServiceError {
127
+ constructor(errors) {
128
+ super({
129
+ code: AuthorizationError.CODE,
130
+ status: 401,
131
+ description: 'Authorization failed',
132
+ details: errors
133
+ });
134
+ }
135
+ }
136
+ AuthorizationError.CODE = ErrorCode.PSYNC_S2101;
137
+ export class InternalServerError extends ServiceError {
138
+ constructor(err) {
139
+ super({
140
+ code: InternalServerError.CODE,
141
+ severity: ErrorSeverity.ERROR,
142
+ status: 500,
143
+ description: 'Something went wrong',
144
+ details: err.message,
145
+ stack: process.env.NODE_ENV !== 'production' ? err.stack : undefined
146
+ });
147
+ }
148
+ }
149
+ InternalServerError.CODE = ErrorCode.PSYNC_S2001;
150
+ export class RouteNotFound extends ServiceError {
151
+ constructor(path) {
152
+ super({
153
+ code: RouteNotFound.CODE,
154
+ status: 404,
155
+ description: 'The path does not exist on this server',
156
+ details: `The path ${JSON.stringify(path)} does not exist on this server`,
157
+ severity: ErrorSeverity.INFO
158
+ });
159
+ }
160
+ }
161
+ RouteNotFound.CODE = ErrorCode.PSYNC_S2002;
162
+ export class DatabaseConnectionError extends ServiceError {
163
+ constructor(code, message, cause) {
164
+ super({
165
+ code: code,
166
+ status: 500,
167
+ description: message,
168
+ details: `cause: ${cause.message}`,
169
+ stack: process.env.NODE_ENV !== 'production' ? cause.stack : undefined
170
+ });
171
+ this.c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AAC,KAAK;YAC7B,MAAM,EAAE,GAAG;YACX,WAAW,EAAE,sBAAsB;YACnC,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACrE,CAAC,CAAC;IACL,CAAC;;AAXe,wBAAI,GAAG,SAAS,CAAC,WAAW,CAAC;AAc/C,MAAM,OAAO,aAAc,SAAQ,YAAY;IAG7C,YAAY,IAAY;QACtB,KAAK,CAAC;YACJ,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,MAAM,EAAE,GAAG;YACX,WAAW,EAAE,wCAAwC;YACrD,OAAO,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gCAAgC;YACzE,QAAQ,EAAE,aAAa,CAAC,IAAI;SAC7B,CAAC,CAAC;IACL,CAAC;;AAVe,kBAAI,GAAG,SAAS,CAAC,WAAW,CAAC;AAa/C,MAAM,OAAO,uBAAwB,SAAQ,YAAY;IAGvD,YAAY,IAAe,EAAE,OAAe,EAAE,KAAU;QACtD,KAAK,CAAC;YACJ,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,GAAG;YACX,WAAW,EAAE,OAAO;YACpB,OAAO,EAAE,UAAU,KAAK,CAAC,OAAO,EAAE;YAClC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACvE,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from './errors.js';
2
+ export * from './codes.js';
3
+ export * from './utils.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './errors.js';
2
+ export * from './codes.js';
3
+ export * from './utils.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ErrorData, ServiceError } from './errors.js';
2
+ export declare const isServiceError: (err: any) => err is ServiceError;
3
+ export declare const asServiceError: (err: any) => ServiceError;
4
+ export declare const getErrorData: (err: Error | any) => ErrorData | undefined;
5
+ export declare const matchesErrorCode: (err: Error | any, code: string) => boolean;
package/dist/utils.js ADDED
@@ -0,0 +1,26 @@
1
+ import { InternalServerError, ServiceError } from './errors.js';
2
+ export const isServiceError = (err) => {
3
+ const matches = ServiceError.isServiceError(err);
4
+ return !!matches;
5
+ };
6
+ export const asServiceError = (err) => {
7
+ if (ServiceError.isServiceError(err)) {
8
+ return err;
9
+ }
10
+ else {
11
+ return new InternalServerError(err);
12
+ }
13
+ };
14
+ export const getErrorData = (err) => {
15
+ if (!isServiceError(err)) {
16
+ return;
17
+ }
18
+ return err.toJSON();
19
+ };
20
+ export const matchesErrorCode = (err, code) => {
21
+ if (isServiceError(err)) {
22
+ return err.errorData.code === code;
23
+ }
24
+ return false;
25
+ };
26
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,mBAAmB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAuB,EAAE;IAC9D,MAAM,OAAO,GAAG,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACjD,OAAO,CAAC,CAAC,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAgB,EAAE;IACvD,IAAI,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,OAAO,GAAG,CAAC;IACb,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAgB,EAAyB,EAAE;IACtE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAgB,EAAE,IAAY,EAAE,EAAE;IACjE,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC;IACrC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@powersync/service-errors",
3
+ "repository": "https://github.com/powersync-ja/powersync-service",
4
+ "version": "0.0.0-dev-20250122110924",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "FSL-1.1-Apache-2.0",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "files": [
12
+ "dist/**/*"
13
+ ],
14
+ "type": "module",
15
+ "dependencies": {},
16
+ "devDependencies": {},
17
+ "scripts": {
18
+ "clean": "rm -r ./dist && tsc -b --clean",
19
+ "build": "tsc -b",
20
+ "build:tests": "tsc -b test/tsconfig.json",
21
+ "test": "vitest"
22
+ }
23
+ }