arcadible 1.0.42 → 1.0.44

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.
Files changed (41) hide show
  1. package/dist/action/delete/tool.js +2 -2
  2. package/dist/action/deploy/tool.js +5 -5
  3. package/dist/action/function/logs.js +102 -30
  4. package/dist/action/function/tool.js +2 -2
  5. package/dist/action/game.js +10 -8
  6. package/dist/action/init/tool.js +26 -4
  7. package/dist/action/key/tool.js +5 -5
  8. package/dist/action/pack/tool.js +2 -2
  9. package/dist/action/predeploy/ac.js +4 -4
  10. package/dist/action/secret/tool.js +9 -8
  11. package/dist/action/serve/tool.js +3 -3
  12. package/dist/action/value/tool.js +6 -6
  13. package/dist/action/wire/tool.js +2 -2
  14. package/dist/api.js +2 -2
  15. package/dist/command/init.js +2 -2
  16. package/dist/config/code.js +22 -20
  17. package/dist/config/retry.js +105 -0
  18. package/dist/phrase/deploy.js +2 -2
  19. package/dist/phrase/function.js +2 -2
  20. package/dist/phrase/game.js +1 -1
  21. package/dist/phrase/init.js +7 -1
  22. package/dist/phrase/pack.js +6 -1
  23. package/dist/phrase/server.js +1 -1
  24. package/dist/runner/bundle.js +2 -2
  25. package/dist/runner/outbound.js +2 -0
  26. package/dist/schema/game.js +1 -1
  27. package/dist/serve/message.js +79 -0
  28. package/dist/serve/page.js +70 -60
  29. package/dist/serve/retry.js +4 -8
  30. package/dist/serve/runner.js +15 -6
  31. package/dist/serve/ticket.js +5 -5
  32. package/dist/serve/wires.js +10 -6
  33. package/dist/util/error.js +28 -8
  34. package/dist/util/http.js +6 -2
  35. package/dist/util/output.js +54 -16
  36. package/dist/util/request.js +2 -1
  37. package/dist/util/s3.js +1 -1
  38. package/dist/util/schema.js +4 -2
  39. package/dist/wires/room.js +30 -37
  40. package/npm-shrinkwrap.json +67 -67
  41. package/package.json +2 -2
@@ -2,7 +2,7 @@
2
2
  // for players at once, with every build, and it can't be undone. Nothing in
3
3
  // the project changes.
4
4
  import { deleteGame } from "../../api.js";
5
- import { GAME_ID_MISSING, GAME_UNAVAILABLE } from "../../config/code.js";
5
+ import { GAME_ID_MISSING, GAME_NOT_FOUND } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
7
  import { headersOf, isStatus } from "../game.js";
8
8
  import { given } from "../../parser/given.js";
@@ -38,7 +38,7 @@ export async function deleteTool(current, { id }) {
38
38
  }
39
39
  catch (err) {
40
40
  if (isStatus(err, 404)) {
41
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
41
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
42
42
  cause: err,
43
43
  });
44
44
  }
@@ -1,11 +1,11 @@
1
1
  // [import]
2
2
  import { authed } from "../../account.js";
3
3
  import { postUpload } from "../../api.js";
4
- import { DEPLOY_RATE_LIMITED, GAME_UNAVAILABLE } from "../../config/code.js";
4
+ import { DEPLOY_RATE_LIMITED, GAME_NOT_FOUND } from "../../config/code.js";
5
5
  import { ArcError } from "../../util/error.js";
6
6
  import { releasing } from "../predeploy/game.js";
7
7
  import { isRefused } from "../game.js";
8
- import { deployRateLimited, gameUnavailable } from "../../phrase/index.js";
8
+ import { deployRateLimited, gameDeletedOrNotOwned, } from "../../phrase/index.js";
9
9
  import { published } from "../../util/links.js";
10
10
  import { upload as s3Upload } from "../../util/s3.js";
11
11
  // [function]
@@ -20,10 +20,10 @@ function uploadBuild(current, artifact, { id, version }, onProgress) {
20
20
  form.append("size", String(artifact.size));
21
21
  return authed(current, (headers) => postUpload(form, null, headers)).then((upload) => s3Upload(upload.upload_url, artifact, onProgress).then(() => upload), (err) => {
22
22
  // the API refuses a game that was deleted or is another account's
23
- // (403), and the same version deployed again within 5 minutes (429),
23
+ // (404), and the same version deployed again within 5 minutes (429),
24
24
  // each by its code.
25
- if (isRefused(err, GAME_UNAVAILABLE, 403)) {
26
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
25
+ if (isRefused(err, GAME_NOT_FOUND, 404)) {
26
+ throw new ArcError(GAME_NOT_FOUND, gameDeletedOrNotOwned(id), {
27
27
  cause: err,
28
28
  });
29
29
  }
@@ -6,12 +6,13 @@
6
6
  // [import]
7
7
  import { WebSocket } from "ws";
8
8
  import { postGameFunctionLogsToken } from "../../api.js";
9
- import { API_REFUSED, API_UNREACHABLE, ARGUMENT_INVALID, GAME_UNAVAILABLE, INTERNAL, } from "../../config/code.js";
10
- import { ArcError } from "../../util/error.js";
9
+ import { API_UNREACHABLE, ARGUMENT_INVALID, FUNCTION_LOGS_FOLLOWS_FULL, GAME_NOT_FOUND, UNAVAILABLE, UNEXPECTED, } from "../../config/code.js";
10
+ import { ArcError, codeOf } from "../../util/error.js";
11
+ import { HttpError } from "../../util/http.js";
11
12
  import { sleep } from "../../util/delay.js";
12
13
  import { isTable } from "../../util/objs.js";
13
14
  import { channelOf, gameOf, headersOf, isStatus } from "../game.js";
14
- import { answerUnread, functionLogsBusy, functionLogsRefused, functionLogsSinceInvalid, functionLogsVersionInvalid, gameNotOwned, unableToReach, } from "../../phrase/index.js";
15
+ import { answerUnread, functionLogsFull, functionLogsRefused, functionLogsSinceInvalid, functionLogsVersionInvalid, gameNotOwned, unableToReach, } from "../../phrase/index.js";
15
16
  // [declare]
16
17
  // the protocol a follow speaks, offered with the token beside it, and the
17
18
  // code it's closed with at its hour (the logs Worker's src/logs.js and
@@ -81,29 +82,70 @@ function isEntry(value) {
81
82
  typeof value["at"] === "number");
82
83
  }
83
84
  // [function]
84
- // the Worker's refusal as the CLI's failure: Arcadible's side (a 5xx) is
85
- // internal, and anything else api_refused, never a 401 that would end the
85
+ // the Worker's refusal as the CLI's failure, read as the API's is (codeOf):
86
+ // its code where it's one of the CLI's, unavailable for a 5xx with none,
87
+ // and api_refused for anything else, never a 401 that would end the
86
88
  // session, since the token isn't the session's.
87
- function refused(status, code) {
88
- return new ArcError(status >= 500 ? INTERNAL : API_REFUSED, functionLogsRefused({ code, status }));
89
+ function refused(status, said) {
90
+ // the Worker's own code, retry, and status go with the failure, as its
91
+ // cause
92
+ const told = httpErrorOf(status, said);
93
+ const { code } = said;
94
+ return new ArcError(codeOf(told), functionLogsRefused({ code, status }), {
95
+ cause: told,
96
+ status,
97
+ });
98
+ }
99
+ // [function]
100
+ // a new token refused as expired too: Arcadible's own trouble with its own
101
+ // token, which getting another didn't mend, so it's unavailable (ERRORS.md,
102
+ // Passing a code on), carrying the refusal.
103
+ function tokenRefused(said) {
104
+ return new ArcError(UNAVAILABLE, functionLogsRefused({ code: "expired", status: 401 }), { cause: httpErrorOf(401, { ...said, code: "expired" }), status: 401 });
105
+ }
106
+ // [function]
107
+ // the Worker's refusal as an HttpError, with what it said.
108
+ function httpErrorOf(status, { code, retry }) {
109
+ return new HttpError(status, {
110
+ ...(code === null ? {} : { code }),
111
+ ...(retry === null ? {} : { retry }),
112
+ });
113
+ }
114
+ // [function]
115
+ // what a refusal's body said: its code and retry, each null when it said
116
+ // none, or the body isn't JSON.
117
+ function toldIn(body) {
118
+ const said = (key) => isTable(body) && typeof body[key] === "string" ? body[key] : null;
119
+ return { code: said("code"), retry: said("retry") };
120
+ }
121
+ // [function]
122
+ // what a refusal's text said, as toldIn.
123
+ function toldInText(text) {
124
+ try {
125
+ return toldIn(JSON.parse(text));
126
+ }
127
+ catch {
128
+ return toldIn(null);
129
+ }
89
130
  }
90
131
  // [function]
91
132
  // a token for the game's logs: the game is the caller's, or
92
- // game_unavailable, as for the rest of `arc unstable function`.
133
+ // game_not_found, as for the rest of `arc unstable function`.
93
134
  async function tokenOf(id, headers) {
94
135
  try {
95
136
  return await postGameFunctionLogsToken(id, null, headers);
96
137
  }
97
138
  catch (err) {
98
139
  if (isStatus(err, 404)) {
99
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), { cause: err });
140
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), { cause: err });
100
141
  }
101
142
  throw err;
102
143
  }
103
144
  }
104
145
  // [function]
105
- // the newest page, newest first, or null when the token had expired.
106
- async function pageOf(token, query) {
146
+ // the newest page, newest first, or null when the token had expired. A
147
+ // token that expired on the `last` try is unavailable (tokenRefused).
148
+ async function pageOf(token, query, last) {
107
149
  let res;
108
150
  try {
109
151
  res = await fetch(query.size ? `${token.url}?${query.toString()}` : token.url, {
@@ -122,30 +164,32 @@ async function pageOf(token, query) {
122
164
  }
123
165
  }, () => null);
124
166
  if (!res.ok) {
125
- const code = isTable(body) && typeof body["code"] === "string" ? body["code"] : null;
126
- if (res.status === 401 && code === "expired")
167
+ const told = toldIn(body);
168
+ if (res.status === 401 && told.code === "expired") {
169
+ if (last)
170
+ throw tokenRefused(told);
127
171
  return null;
128
- throw refused(res.status, code);
172
+ }
173
+ throw refused(res.status, told);
129
174
  }
130
175
  if (!isPage(body)) {
131
- throw new ArcError(INTERNAL, answerUnread("a function's logs"));
176
+ throw new ArcError(UNEXPECTED, answerUnread("a function's logs"));
132
177
  }
133
178
  return body.data;
134
179
  }
135
180
  // [function]
136
181
  // the game's newest entries that match, at most 100, newest first. A token
137
- // that ended on its way is asked for again, once.
182
+ // that ended on its way is asked for again, once, and a second refused is
183
+ // unavailable.
138
184
  export async function logs(current, { channel, ...conf }) {
139
185
  const where = channelOf(channel);
140
186
  const query = queryOf(conf, where);
141
187
  const id = await gameOf(conf);
142
188
  const headers = headersOf(current);
143
189
  for (let tries = 0;; tries += 1) {
144
- const page = await pageOf(await tokenOf(id, headers), query);
190
+ const page = await pageOf(await tokenOf(id, headers), query, tries > 0);
145
191
  if (page)
146
192
  return page;
147
- if (tries)
148
- throw refused(401, "expired");
149
193
  }
150
194
  }
151
195
  // [function]
@@ -159,19 +203,31 @@ function followOnce(token, query, shown) {
159
203
  let opened = false;
160
204
  let done = false;
161
205
  let pinging = null;
162
- const end = (status) => {
206
+ const end = (status, told = toldIn(null)) => {
163
207
  if (done)
164
208
  return;
165
209
  done = true;
166
210
  if (pinging)
167
211
  clearInterval(pinging);
168
- resolve({ opened, status });
212
+ resolve({ ...told, opened, status });
169
213
  };
170
214
  const socket = new WebSocket(url.href, [PROTOCOL, token.token]);
215
+ // a refusal's body says its code and retry, read before the
216
+ // connection's dropped
171
217
  socket.on("unexpected-response", (req, res) => {
172
- req.destroy();
173
- res.resume();
174
- end(res.statusCode ?? 500);
218
+ const chunks = [];
219
+ const status = res.statusCode ?? 500;
220
+ res.on("data", (chunk) => {
221
+ chunks.push(chunk);
222
+ });
223
+ res.on("end", () => {
224
+ req.destroy();
225
+ end(status, toldInText(Buffer.concat(chunks).toString("utf8")));
226
+ });
227
+ res.on("error", () => {
228
+ req.destroy();
229
+ end(status);
230
+ });
175
231
  });
176
232
  socket.on("open", () => {
177
233
  opened = true;
@@ -202,8 +258,12 @@ function followOnce(token, query, shown) {
202
258
  // the game's newest entries that match, then each new one as it comes,
203
259
  // until the command is stopped: `shown` is given each once, oldest first.
204
260
  // A follow closes at its hour, or when the connection drops, and is opened
205
- // again with a new token; one the Worker refuses ends the command, and so
206
- // does one that can't be opened five times in a row.
261
+ // again with a new token, as is one refused as expired or by Arcadible's
262
+ // side; one the Worker refuses otherwise ends the command, a sixth follow
263
+ // as function_logs_follows_full, and so does one that can't be opened five
264
+ // times in a row: unavailable when the last was a token refused as
265
+ // expired, as a page's second is, else as the last refusal it was told,
266
+ // carried, or api_unreachable when nothing answered.
207
267
  export async function follow(current, { channel, ...conf }, shown) {
208
268
  const where = channelOf(channel);
209
269
  const query = queryOf(conf, where);
@@ -225,13 +285,25 @@ export async function follow(current, { channel, ...conf }, shown) {
225
285
  query.delete("since");
226
286
  for (let failed = 0;;) {
227
287
  const closed = await followOnce(await tokenOf(id, headers), query, once);
228
- if (closed.status === 429)
229
- throw new ArcError(API_REFUSED, functionLogsBusy());
230
- if (closed.status && closed.status < 500 && closed.status !== 401) {
231
- throw refused(closed.status, null);
288
+ const { code, status } = closed;
289
+ // read by the Worker's code alone, as a page is (`pageOf`): a bare 401
290
+ // is refused as any other 4xx, and a bare 507 tried again as a 5xx
291
+ if (code === "full") {
292
+ throw new ArcError(FUNCTION_LOGS_FOLLOWS_FULL, functionLogsFull(), {
293
+ cause: httpErrorOf(status ?? 507, closed),
294
+ status: status ?? 507,
295
+ });
296
+ }
297
+ const expired = status === 401 && code === "expired";
298
+ if (status && status < 500 && !expired) {
299
+ throw refused(status, closed);
232
300
  }
233
301
  failed = closed.opened ? 0 : failed + 1;
234
302
  if (failed >= TRIES) {
303
+ if (expired)
304
+ throw tokenRefused(closed);
305
+ if (status)
306
+ throw refused(status, closed);
235
307
  throw new ArcError(API_UNREACHABLE, unableToReach());
236
308
  }
237
309
  // a follow that opened and closed is opened again after a second at
@@ -3,7 +3,7 @@
3
3
  // too, and so can its allowance, spent: a pause has a reason, and an owner
4
4
  // lifts only their own.
5
5
  import { deleteGameFunctionPause, discoverGameBuilds, gameFunctionPauses, gameFunctionUsages, putGameFunctionPause, } from "../../api.js";
6
- import { FUNCTION_PAUSE_NOT_OWNED, GAME_UNAVAILABLE, } from "../../config/code.js";
6
+ import { FUNCTION_PAUSE_NOT_OWNED, GAME_NOT_FOUND } from "../../config/code.js";
7
7
  import { ArcError } from "../../util/error.js";
8
8
  import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, ownedOf, } from "../game.js";
9
9
  import { functionPauseNotOwned, gameNotOwned } from "../../phrase/index.js";
@@ -62,7 +62,7 @@ export async function pause(current, { channel, ...conf }) {
62
62
  }
63
63
  catch (err) {
64
64
  if (isStatus(err, 404)) {
65
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
65
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
66
66
  cause: err,
67
67
  });
68
68
  }
@@ -3,7 +3,7 @@
3
3
  // command names, the session's headers, and telling the API's refusals
4
4
  // apart.
5
5
  import { auth, gameWireUsages } from "../api.js";
6
- import { ALL, ARGUMENT_INVALID, GAME_ID_MISSING, GAME_UNAVAILABLE, NOT_LOGGED_IN, } from "../config/code.js";
6
+ import { ARGUMENT_INVALID, GAME_ID_MISSING, GAME_NOT_FOUND, NOT_LOGGED_IN, } from "../config/code.js";
7
7
  import { ArcError } from "../util/error.js";
8
8
  import { given } from "../parser/given.js";
9
9
  import { HttpError } from "../util/http.js";
@@ -59,12 +59,12 @@ export function headersOf(current) {
59
59
  // that the game is the caller's, asked before a read the API answers as
60
60
  // none for another account's game (its keys, its function's secrets,
61
61
  // pauses, and usage): its owner always reads today's wire usage for each
62
- // channel, so none at all is a game that isn't theirs, game_unavailable,
62
+ // channel, so none at all is a game that isn't theirs, game_not_found,
63
63
  // as `arc unstable wire usage` says.
64
64
  export async function ownedOf(id, headers) {
65
65
  const rows = await gameWireUsages(id, null, headers);
66
66
  if (!rows?.length) {
67
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id));
67
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id));
68
68
  }
69
69
  }
70
70
  // [function]
@@ -74,12 +74,14 @@ export function isStatus(err, status) {
74
74
  }
75
75
  // [function]
76
76
  // whether a failure is the API's refusal with this code, which the
77
- // database names (ERRORS.md): read first, and, from an API that doesn't say
78
- // one, its status.
77
+ // database names (ERRORS.md): the code alone when the answer says one, and
78
+ // its status only when it says none (a proxy's page, which names nothing).
79
+ // Another code with the same status is another refusal: a 429 `busy` on an
80
+ // upload is never `deploy_rate_limited`.
79
81
  export function isRefused(err, code, status) {
80
82
  if (!(err instanceof HttpError))
81
83
  return false;
82
- if (err.code === code)
83
- return true;
84
- return (err.status === status && (err.code === undefined || !ALL.has(err.code)));
84
+ if (err.code !== undefined)
85
+ return err.code === code;
86
+ return err.status === status;
85
87
  }
@@ -4,9 +4,10 @@ import { createRequire } from "node:module";
4
4
  import { join, resolve } from "node:path";
5
5
  import fs from "fs-extra";
6
6
  // [import]
7
- import { TEMPLATE_UNAVAILABLE } from "../../config/code.js";
7
+ import { API_UNREACHABLE, TEMPLATE_NOT_FOUND } from "../../config/code.js";
8
8
  import { ArcError } from "../../util/error.js";
9
- import { templateUnavailable } from "../../phrase/index.js";
9
+ import { isTable } from "../../util/objs.js";
10
+ import { templateNotFound, templateUnreachable } from "../../phrase/index.js";
10
11
  import { detectVersion, prepare } from "./manifest.js";
11
12
  import { choices } from "../../config/template.js";
12
13
  // [use]
@@ -24,10 +25,31 @@ function removeLicense(dest) {
24
25
  return remove(join(dest, LICENSE));
25
26
  }
26
27
  // [function]
27
- // a starter's name on its own, such as `blank`, suggests the starter.
28
+ // whether degit's failure got no response from GitHub: `git ls-remote`
29
+ // unable to reach it (git says "unable to access" for any failure of the
30
+ // connection), or the archive's download failing as a system error
31
+ // (ENOTFOUND, ECONNRESET), not a status. A repository that isn't there, or
32
+ // isn't public, is git asking for a username, or a 404.
33
+ function unreached(ex) {
34
+ if (!isTable(ex) || !isTable(ex["original"]))
35
+ return false;
36
+ const original = ex["original"];
37
+ if (ex["code"] === "COULD_NOT_FETCH") {
38
+ const said = original["message"];
39
+ return typeof said === "string" && said.includes("unable to access");
40
+ }
41
+ return (ex["code"] === "COULD_NOT_DOWNLOAD" && typeof original["code"] === "string");
42
+ }
43
+ // [function]
44
+ // the template's download failed: api_unreachable where nothing answered,
45
+ // else template_not_found, whose starter's name on its own, such as
46
+ // `blank`, suggests the starter.
28
47
  function unavailable(src, cause) {
48
+ if (unreached(cause)) {
49
+ return new ArcError(API_UNREACHABLE, templateUnreachable(src), { cause });
50
+ }
29
51
  const starter = choices.find(({ value }) => value.split("/").pop() === src);
30
- return new ArcError(TEMPLATE_UNAVAILABLE, templateUnavailable(src, starter?.value), { cause });
52
+ return new ArcError(TEMPLATE_NOT_FOUND, templateNotFound(src, starter?.value), { cause });
31
53
  }
32
54
  // [function]
33
55
  // degit copies nothing, without failing, from a folder a repository doesn't
@@ -2,10 +2,10 @@
2
2
  // is for one game and one channel, made by the game's owner, shown once, and
3
3
  // revoked at once. Nothing here keeps one.
4
4
  import { deleteKey, gameKeys, postGameKey, } from "../../api.js";
5
- import { ARGUMENT_INVALID, GAME_UNAVAILABLE, KEY_LIMIT_REACHED, KEY_NOT_FOUND, } from "../../config/code.js";
5
+ import { ARGUMENT_INVALID, GAME_NOT_FOUND, KEY_QUOTA_FULL, KEY_NOT_FOUND, } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
7
  import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, ownedOf, } from "../game.js";
8
- import { gameNotOwned, keyLimitReached, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
8
+ import { gameNotOwned, keyQuotaFull, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
9
9
  // [declare]
10
10
  const NAME_MAX = 64;
11
11
  // the name a key gets when none is given.
@@ -36,12 +36,12 @@ export async function create(current, { channel, name, ...conf }) {
36
36
  }
37
37
  catch (err) {
38
38
  if (isStatus(err, 404)) {
39
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
39
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
40
40
  cause: err,
41
41
  });
42
42
  }
43
- if (isRefused(err, KEY_LIMIT_REACHED, 409)) {
44
- throw new ArcError(KEY_LIMIT_REACHED, keyLimitReached(where), {
43
+ if (isRefused(err, KEY_QUOTA_FULL, 507)) {
44
+ throw new ArcError(KEY_QUOTA_FULL, keyQuotaFull(where), {
45
45
  cause: err,
46
46
  });
47
47
  }
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { pathExists } from "fs-extra";
5
5
  // [import]
6
6
  import { BUILT, PACKED } from "../../runner/bundle.js";
7
- import { DEPLOY_DIR_MISSING, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PATH_NOT_FOUND, } from "../../config/code.js";
7
+ import { DEPLOY_DIR_MISSING, FUNCTION_NOT_BUILT, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PATH_NOT_FOUND, } from "../../config/code.js";
8
8
  import { ArcError } from "../../util/error.js";
9
9
  import { MEDIA, PACKAGED } from "../../config/file.js";
10
10
  import { deployDirMissing, packageIndexMissing, packagePathReserved, packageTooLarge, runnerNotBuilt, unableToFind, } from "../../phrase/index.js";
@@ -142,7 +142,7 @@ function pack(name, game, { deployDir, icon, inputPath, mediaPath, onWarning, ou
142
142
  // the runner's bundle, as `arc build` wrote it, in the folder every
143
143
  // build's origin keeps for Arcadible's own files, which is never served
144
144
  if (runner && !built) {
145
- throw new ArcError(PATH_NOT_FOUND, runnerNotBuilt());
145
+ throw new ArcError(FUNCTION_NOT_BUILT, runnerNotBuilt());
146
146
  }
147
147
  if (runner) {
148
148
  zip.addFile(runner.built, PACKED);
@@ -1,9 +1,9 @@
1
1
  // [import]
2
2
  import { auth, discoverGame, gameBuild, gameHandle } from "../../api.js";
3
- import { GAME_HANDLE_TAKEN, GAME_UNAVAILABLE, WARNING, } from "../../config/code.js";
3
+ import { GAME_HANDLE_TAKEN, GAME_NOT_FOUND, WARNING, } from "../../config/code.js";
4
4
  import { ArcError } from "../../util/error.js";
5
5
  import { HttpError } from "../../util/http.js";
6
- import { gameHandleLapsed, gameHandleLimit, gameHandleTaken, gameUnavailable, } from "../../phrase/index.js";
6
+ import { gameHandleLapsed, gameHandleLimit, gameHandleTaken, gameDeletedOrNotOwned, } from "../../phrase/index.js";
7
7
  import { channel } from "../../util/links.js";
8
8
  import { refuse } from "./published.js";
9
9
  // [function]
@@ -22,7 +22,7 @@ function ensureOwned(current, id) {
22
22
  // a token's account isn't known yet; the server checks ownership when
23
23
  // it authorizes the upload.
24
24
  if (!current?.token && game.account !== current?.user.id) {
25
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id));
25
+ throw new ArcError(GAME_NOT_FOUND, gameDeletedOrNotOwned(id));
26
26
  }
27
27
  }, ignoreMissing);
28
28
  }
@@ -46,7 +46,7 @@ function ensureHandle(current, { handle, id, version }, handler) {
46
46
  throw new ArcError(GAME_HANDLE_TAKEN, gameHandleTaken(handle));
47
47
  }
48
48
  if (status === "limit") {
49
- warn(WARNING.GAME_HANDLE_LIMIT_REACHED, gameHandleLimit(handle));
49
+ warn(WARNING.GAME_HANDLE_QUOTA_FULL, gameHandleLimit(handle));
50
50
  return true;
51
51
  }
52
52
  if (status === "lapsed") {
@@ -3,11 +3,11 @@
3
3
  // channel, by the name the manifest declares (function.secrets), set by the
4
4
  // game's owner, and never shown again. Nothing here keeps one.
5
5
  import { deleteGameFunctionSecret, gameFunctionSecrets, putGameFunctionSecret, } from "../../api.js";
6
- import { ARGUMENT_INVALID, GAME_UNAVAILABLE, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, } from "../../config/code.js";
6
+ import { ARGUMENT_INVALID, GAME_NOT_FOUND, SECRET_QUOTA_FULL, SECRET_NOT_FOUND, SECRET_TOO_LARGE, } from "../../config/code.js";
7
7
  import { SECRET_NAME } from "../../config/limit.js";
8
8
  import { ArcError } from "../../util/error.js";
9
9
  import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, ownedOf, } from "../game.js";
10
- import { gameNotOwned, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
10
+ import { gameNotOwned, secretQuotaFull, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
11
11
  // [declare]
12
12
  const VALUE_MAX = 4096;
13
13
  // [function]
@@ -27,11 +27,12 @@ export async function set(current, { channel, name, value, ...conf }) {
27
27
  const id = await gameOf(conf);
28
28
  const headers = headersOf(current);
29
29
  const secret = await value();
30
- if (typeof secret !== "string" ||
31
- secret === "" ||
32
- Buffer.byteLength(secret) > VALUE_MAX) {
30
+ if (typeof secret !== "string" || secret === "") {
33
31
  throw new ArcError(ARGUMENT_INVALID, secretValueInvalid());
34
32
  }
33
+ if (Buffer.byteLength(secret) > VALUE_MAX) {
34
+ throw new ArcError(SECRET_TOO_LARGE, secretValueInvalid());
35
+ }
35
36
  const form = new FormData();
36
37
  form.append("value", secret);
37
38
  try {
@@ -40,12 +41,12 @@ export async function set(current, { channel, name, value, ...conf }) {
40
41
  }
41
42
  catch (err) {
42
43
  if (isStatus(err, 404)) {
43
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
44
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
44
45
  cause: err,
45
46
  });
46
47
  }
47
- if (isRefused(err, SECRET_LIMIT_REACHED, 409)) {
48
- throw new ArcError(SECRET_LIMIT_REACHED, secretLimitReached(where), {
48
+ if (isRefused(err, SECRET_QUOTA_FULL, 507)) {
49
+ throw new ArcError(SECRET_QUOTA_FULL, secretQuotaFull(where), {
49
50
  cause: err,
50
51
  });
51
52
  }
@@ -9,7 +9,7 @@ import { setTimeout as sleep } from "node:timers/promises";
9
9
  // [import]
10
10
  import { pathExists } from "fs-extra";
11
11
  // [import]
12
- import { ARGUMENT_INVALID, DEPLOY_DIR_MISSING, PORT_IN_USE, } from "../../config/code.js";
12
+ import { ARGUMENT_INVALID, DEPLOY_DIR_MISSING, PORT_IN_USE, VALIDATION_FAILED, } from "../../config/code.js";
13
13
  import { clientNames } from "../../schema/client.js";
14
14
  import { buildCommand } from "../../util/command.js";
15
15
  import { ArcError } from "../../util/error.js";
@@ -269,10 +269,10 @@ export async function serveTool(conf) {
269
269
  };
270
270
  }
271
271
  // arc serve validates nothing, so a deploy_dir that isn't a path is said
272
- // as what it is, a folder that isn't there
272
+ // here, as the rule arc validate holds it to
273
273
  const dir = project.workflow.deploy_dir;
274
274
  if (typeof dir !== "string") {
275
- throw new ArcError(DEPLOY_DIR_MISSING, phrase.deployDirMissing(textOf(dir) || "deploy_dir"));
275
+ throw new ArcError(VALIDATION_FAILED, phrase.deployDirNotPath(textOf(dir) || "deploy_dir"));
276
276
  }
277
277
  const built = conf.build !== false && Boolean(buildCommand(project.workflow.build));
278
278
  if (built) {
@@ -6,7 +6,7 @@
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import { gameValuesList, gameValuesRead, gameValuesRemove, gameValuesWrite, gameValueCalls, gameValueUsages, } from "../../api.js";
9
- import { ARGUMENT_INVALID, GAME_UNAVAILABLE, LIMIT_REACHED, VALUE_NOT_FOUND, VALUE_STORAGE_FULL, VALUE_TOO_LARGE, } from "../../config/code.js";
9
+ import { ARGUMENT_INVALID, GAME_NOT_FOUND, LIMIT_REACHED, PARSE_FAILED, PATH_NOT_FOUND, VALUE_NOT_FOUND, VALUE_STORAGE_QUOTA_FULL, VALUE_TOO_LARGE, } from "../../config/code.js";
10
10
  import { ArcError } from "../../util/error.js";
11
11
  import { HttpError } from "../../util/http.js";
12
12
  import { gameOf, headersOf, isStatus, needOf } from "../game.js";
@@ -36,7 +36,7 @@ function parsed(text, source) {
36
36
  return JSON.parse(text);
37
37
  }
38
38
  catch (err) {
39
- throw new ArcError(ARGUMENT_INVALID, valueNotJson(source), { cause: err });
39
+ throw new ArcError(PARSE_FAILED, valueNotJson(source), { cause: err });
40
40
  }
41
41
  }
42
42
  // [function]
@@ -45,7 +45,7 @@ function fileOf(file) {
45
45
  return fs.readFileSync(file, "utf8");
46
46
  }
47
47
  catch (err) {
48
- throw new ArcError(ARGUMENT_INVALID, valueFileUnread(file), { cause: err });
48
+ throw new ArcError(PATH_NOT_FOUND, valueFileUnread(file), { cause: err });
49
49
  }
50
50
  }
51
51
  // [function]
@@ -57,7 +57,7 @@ function folderOf(dir) {
57
57
  names = fs.readdirSync(dir, { recursive: true });
58
58
  }
59
59
  catch (err) {
60
- throw new ArcError(ARGUMENT_INVALID, valueFileUnread(dir), { cause: err });
60
+ throw new ArcError(PATH_NOT_FOUND, valueFileUnread(dir), { cause: err });
61
61
  }
62
62
  const items = names
63
63
  .filter((name) => name.endsWith(FILE))
@@ -112,12 +112,12 @@ async function holds(id, channel, headers) {
112
112
  function refused(id, channel, headers) {
113
113
  return async (err) => {
114
114
  if (isStatus(err, 404)) {
115
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
115
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
116
116
  cause: err,
117
117
  });
118
118
  }
119
119
  if (isStatus(err, 507)) {
120
- throw new ArcError(VALUE_STORAGE_FULL, valueFull(channel, await holds(id, channel, headers)), { cause: err });
120
+ throw new ArcError(VALUE_STORAGE_QUOTA_FULL, valueFull(channel, await holds(id, channel, headers)), { cause: err });
121
121
  }
122
122
  if (err instanceof HttpError && err.code === LIMIT_REACHED) {
123
123
  throw new ArcError(LIMIT_REACHED, valueCallsSpent(), { cause: err });
@@ -2,7 +2,7 @@
2
2
  // players. What its owner sees of them is their usage: wires keep nothing,
3
3
  // and nothing about one is set from here.
4
4
  import { gameWireUsages } from "../../api.js";
5
- import { GAME_UNAVAILABLE } from "../../config/code.js";
5
+ import { GAME_NOT_FOUND } from "../../config/code.js";
6
6
  import { ArcError } from "../../util/error.js";
7
7
  import { channelOf, CHANNELS, gameOf, headersOf, } from "../game.js";
8
8
  import { gameNotOwned } from "../../phrase/index.js";
@@ -16,7 +16,7 @@ export async function usage(current, { channel, ...conf }) {
16
16
  // its owner always reads today's row for each channel: no rows at all is
17
17
  // a game that isn't the caller's
18
18
  if (rows.length === 0) {
19
- throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id));
19
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id));
20
20
  }
21
21
  const today = new Date().toISOString().slice(0, 10);
22
22
  const sum = (of) => ({
package/dist/api.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // [import]
2
- import { INTERNAL } from "./config/code.js";
2
+ import { UNEXPECTED } from "./config/code.js";
3
3
  import { ArcError } from "./util/error.js";
4
4
  import { answerUnread } from "./phrase/index.js";
5
5
  import { del, get, post, postJson, put } from "./util/request.js";
@@ -144,7 +144,7 @@ const isUsage = shaped({
144
144
  function answer(is, what, data) {
145
145
  return data.then((value) => {
146
146
  if (!is(value)) {
147
- throw new ArcError(INTERNAL, answerUnread(what));
147
+ throw new ArcError(UNEXPECTED, answerUnread(what));
148
148
  }
149
149
  return value;
150
150
  });
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
3
3
  // [import]
4
4
  import fs from "fs-extra";
5
5
  // [import]
6
- import { TEMPLATE_MISSING } from "../config/code.js";
6
+ import { ARGUMENT_INVALID } from "../config/code.js";
7
7
  import { defineCommand } from "../cli/command.js";
8
8
  import { ArcError } from "../util/error.js";
9
9
  import { initialized, initializedNoStarter, templateMissing, } from "../phrase/index.js";
@@ -39,7 +39,7 @@ async function prompt({ cwd, project, template, yes, }) {
39
39
  if (!template) {
40
40
  // without a terminal, the prompt would read end-of-input and exit.
41
41
  if (!process.stdin.isTTY) {
42
- throw new ArcError(TEMPLATE_MISSING, templateMissing());
42
+ throw new ArcError(ARGUMENT_INVALID, templateMissing());
43
43
  }
44
44
  const answer = await select({
45
45
  choices,