@lunora/errors 1.0.0-alpha.2 → 1.0.0-alpha.21

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/dist/index.d.mts CHANGED
@@ -1,18 +1,5 @@
1
- /**
2
- * The central Lunora error catalog — the single source of truth mapping a
3
- * machine-readable `code` to its transport `status`, a short human `title`, and
4
- * (where useful) an actionable Markdown `hint` plus a `docsUrl`.
5
- *
6
- * This table is consumed everywhere an error is surfaced: the runtime/DO wire
7
- * mappers (status), the client SDK (code discrimination), the CLI renderer and
8
- * the Vite overlay (hint), and the Studio UI (title + hint + docs link). It also
9
- * absorbs the former `@lunora/codegen` "solutions" table (see {@link MESSAGE_SOLUTIONS})
10
- * so codegen build-time errors — which are thrown as plain messages into
11
- * generated code and lose their class identity before a consumer sees them —
12
- * keep their message-matched hints.
13
- */
14
1
  /** Markdown hint: a single string or an array of lines. Shape matches `@visulima/error`'s `hint`. */
15
- type ErrorHint = string | string[];
2
+ type ErrorHint = string | ReadonlyArray<string>;
16
3
  /** A catalog entry: the fixed metadata for one error `code`. */
17
4
  interface ErrorCatalogEntry {
18
5
  /** Optional URL to deeper docs for this error. */
@@ -20,11 +7,11 @@ interface ErrorCatalogEntry {
20
7
  /** Optional actionable fix, authored as Markdown (rendered by CLI/overlay/Studio). */
21
8
  hint?: ErrorHint;
22
9
  /**
23
- * When `true`, this code's `message` must NOT cross the wire — an internal
24
- * failure or unhandled invariant may carry SQL fragments, file paths, or
25
- * internal identifiers. The transport mappers emit a generic message for
26
- * these (and log the real one server-side). See {@link isInternalCode}.
27
- */
10
+ * When `true`, this code's `message` must NOT cross the wire — an internal
11
+ * failure or unhandled invariant may carry SQL fragments, file paths, or
12
+ * internal identifiers. The transport mappers emit a generic message for
13
+ * these (and log the real one server-side). See {@link isInternalCode}.
14
+ */
28
15
  internal?: boolean;
29
16
  /** HTTP/RPC status this code maps to on the wire. */
30
17
  status: number;
@@ -32,10 +19,10 @@ interface ErrorCatalogEntry {
32
19
  title: string;
33
20
  }
34
21
  /**
35
- * Every well-known Lunora error code. Domain packages may throw additional
36
- * codes (passing an explicit `status`); those are added here as their package is
37
- * migrated. The keys of this object form the {@link LunoraErrorCode} union.
38
- */
22
+ * Every well-known Lunora error code. Domain packages may throw additional
23
+ * codes (passing an explicit `status`); those are added here as their package is
24
+ * migrated. The keys of this object form the {@link LunoraErrorCode} union.
25
+ */
39
26
  declare const ERROR_CATALOG: {
40
27
  readonly BAD_REQUEST: {
41
28
  readonly status: 400;
@@ -78,7 +65,8 @@ declare const ERROR_CATALOG: {
78
65
  readonly NOT_IMPLEMENTED: {
79
66
  readonly status: 501;
80
67
  readonly title: "Not implemented";
81
- }; /** RPC/REST dispatch codes emitted by the runtime + Durable Object router. */
68
+ };
69
+ /** RPC/REST dispatch codes emitted by the runtime + Durable Object router. */
82
70
  readonly FUNCTION_NOT_FOUND: {
83
71
  readonly status: 404;
84
72
  readonly title: "Function not found";
@@ -90,7 +78,8 @@ declare const ERROR_CATALOG: {
90
78
  readonly PAYLOAD_TOO_LARGE: {
91
79
  readonly status: 413;
92
80
  readonly title: "Payload too large";
93
- }; /** Free-form internal failure — redacted to a generic message on the wire. */
81
+ };
82
+ /** Free-form internal failure — redacted to a generic message on the wire. */
94
83
  readonly INTERNAL: {
95
84
  readonly internal: true;
96
85
  readonly status: 500;
@@ -125,6 +114,28 @@ declare const ERROR_CATALOG: {
125
114
  readonly status: 403;
126
115
  readonly title: "RLS policy required";
127
116
  };
117
+ readonly RUN_DEPTH_EXCEEDED: {
118
+ readonly internal: true;
119
+ readonly status: 500;
120
+ readonly title: "Run depth exceeded";
121
+ };
122
+ readonly TRANSACTION_LIMIT_EXCEEDED: {
123
+ readonly hint: readonly ["A single mutation may only read and write a bounded amount before it is stopped.", "", "Narrow the read with an index (`.withIndex(...)`) instead of scanning the table, or split the write across several mutations — for a large backfill use `defineMigration` + `lunora migrate up`, which batches and checkpoints for you.", "", "The ceilings are deliberately conservative — they exist to stop one request taking down the whole shard. A deployment that genuinely needs bigger transactions can raise them by overriding the `transactionLimits()` seam on its generated shard class."];
124
+ readonly status: 413;
125
+ readonly title: "Transaction limit exceeded";
126
+ };
127
+ readonly MIGRATION_NOT_FOUND: {
128
+ readonly status: 404;
129
+ readonly title: "Data migration not found";
130
+ };
131
+ readonly UNKNOWN_TABLE: {
132
+ readonly status: 404;
133
+ readonly title: "Unknown table";
134
+ };
135
+ readonly GLOBAL_TABLE_NOT_EDITABLE: {
136
+ readonly status: 400;
137
+ readonly title: "Global table is not editable";
138
+ };
128
139
  readonly SHARD_ERROR: {
129
140
  readonly status: 503;
130
141
  readonly title: "Shard error";
@@ -136,7 +147,8 @@ declare const ERROR_CATALOG: {
136
147
  readonly OFFLINE_IDENTITY_CHANGED: {
137
148
  readonly status: 409;
138
149
  readonly title: "Offline identity changed";
139
- }; /** Package-specific codes. Build-time-only — never cross the RPC wire, so deliberately not `internal`. */
150
+ };
151
+ /** Package-specific codes. Build-time-only — never cross the RPC wire, so deliberately not `internal`. */
140
152
  readonly CODEGEN_DIAGNOSTIC: {
141
153
  readonly status: 500;
142
154
  readonly title: "Codegen diagnostic";
@@ -159,11 +171,31 @@ declare const ERROR_CATALOG: {
159
171
  readonly title: "Auth headers missing";
160
172
  };
161
173
  /**
162
- * Upstream Cloudflare API failures surfaced from an action. The message
163
- * carries the upstream response body (Cloudflare's own error text trusted
164
- * infra, not user input), so it is echoed rather than redacted. `status`
165
- * here is a fallback; each throw passes the actual upstream HTTP status.
166
- */
174
+ * Signup rejected by `@lunora/auth`'s email-domain gate a disposable/throwaway
175
+ * provider (or a caller deny-list hit). Client-safe: the message names only the
176
+ * offending domain class, never a secret, so it is echoed rather than redacted.
177
+ */
178
+ readonly EMAIL_DOMAIN_BLOCKED: {
179
+ readonly hint: readonly ["This address's domain is on the disposable/throwaway blocklist (or your configured deny-list).", "", "Sign up with a permanent mailbox. To tune the policy, pass `blockDisposable` / `allowDomains` / `denyDomains` to `emailGate(...)` (`@lunora/auth/email-guard`)."];
180
+ readonly status: 400;
181
+ readonly title: "Email domain not allowed";
182
+ };
183
+ /**
184
+ * Opt-in MX verification (`@lunora/auth/email-guard`, `mx: true`) found no mail
185
+ * exchanger for the address's domain, so mail to it would never deliver.
186
+ * Client-safe: names only the domain, no secret.
187
+ */
188
+ readonly EMAIL_UNDELIVERABLE: {
189
+ readonly hint: readonly ["The address's domain publishes no MX (or fallback A/AAAA) records, so it can't receive mail.", "", "Check for a typo in the domain. MX verification is opt-in (`mx: true`) and needs DNS — leave it off on the edge path if DNS is unavailable."];
190
+ readonly status: 400;
191
+ readonly title: "Email domain cannot receive mail";
192
+ };
193
+ /**
194
+ * Upstream Cloudflare API failures surfaced from an action. The message
195
+ * carries the upstream response body (Cloudflare's own error text — trusted
196
+ * infra, not user input), so it is echoed rather than redacted. `status`
197
+ * here is a fallback; each throw passes the actual upstream HTTP status.
198
+ */
167
199
  readonly ANALYTICS_SQL_ERROR: {
168
200
  readonly status: 502;
169
201
  readonly title: "Analytics Engine SQL API error";
@@ -176,25 +208,480 @@ declare const ERROR_CATALOG: {
176
208
  readonly status: 502;
177
209
  readonly title: "Cloudflare Workflows REST API error";
178
210
  };
211
+ /**
212
+ * Admin-gated `/_lunora/admin/*` and `__lunora_admin__:*` codes. Registered
213
+ * here (plan 230, ERRORS-01) after an audit found them minted with `code:`
214
+ * but never added to the catalog — `isInternalCode` fails OPEN for an
215
+ * unregistered code, so each was already echoing its message unredacted.
216
+ * Below is that audit's verdict per code, not a blanket allow: most of these
217
+ * are deliberately actionable ("you forgot to configure X") and stay
218
+ * client-safe; the ones that can carry backend detail are flagged
219
+ * `internal: true` individually, with the reason noted alongside.
220
+ */
221
+ readonly ADMIN_FORBIDDEN: {
222
+ readonly status: 403;
223
+ readonly title: "Admin access forbidden";
224
+ };
225
+ readonly ADMIN_TOKEN_NOT_CONFIGURED: {
226
+ readonly status: 400;
227
+ readonly title: "Admin token not configured";
228
+ };
229
+ readonly AUTH_NOT_CONFIGURED: {
230
+ readonly status: 400;
231
+ readonly title: "Auth admin not configured";
232
+ };
233
+ readonly AUTH_OP_NOT_SUPPORTED: {
234
+ readonly status: 400;
235
+ readonly title: "Auth admin operation not supported";
236
+ };
237
+ readonly BACKUP_NOT_CONFIGURED: {
238
+ readonly status: 500;
239
+ readonly title: "Scheduled backup not configured";
240
+ };
241
+ readonly BACKUP_RETENTION_NOT_CONFIGURED: {
242
+ readonly hint: readonly ["`lunora backup prune` removes snapshots past the retention window, and this worker has no window: set `backupRetain` (how many to keep) and `backupCron` (which decides whose snapshots retention owns) on `createWorker`.", "", "Nothing was deleted. A default is deliberately not invented here — retention deleting on its own is exactly what this command exists to replace."];
243
+ readonly status: 400;
244
+ readonly title: "Backup retention window not configured";
245
+ };
246
+ readonly BACKUP_TOO_LARGE: {
247
+ readonly hint: readonly ["The scheduled backup is assembled inside the Worker isolate, so it caps the snapshot it will build. Nothing was written.", "", "The cap is on the NDJSON, not on peak memory: the export fan-out resolves every shard's rows before the first row is encoded, so a snapshot under the cap can still exhaust the isolate. It is set well below the isolate's limit for that reason.", "", "Narrow the snapshot with `backupTables`, or take this backup off-platform with `lunora backup create --bucket`, which runs on a machine rather than in an isolate. Backing up more often does not help — every run is a full snapshot."];
248
+ readonly status: 507;
249
+ readonly title: "Backup too large to assemble in a Worker";
250
+ };
251
+ readonly CRON_JOBS_NOT_CONFIGURED: {
252
+ readonly status: 400;
253
+ readonly title: "Cron jobs not configured";
254
+ };
255
+ readonly CRON_JOB_NOT_FOUND: {
256
+ readonly status: 404;
257
+ readonly title: "Cron job not found";
258
+ };
259
+ readonly EXPORT_TAP_NOT_CONFIGURED: {
260
+ readonly status: 400;
261
+ readonly title: "Export tap not configured";
262
+ };
263
+ readonly FUNCTIONS_NOT_CONFIGURED: {
264
+ readonly status: 400;
265
+ readonly title: "Functions registry not configured";
266
+ };
267
+ readonly GLOBALS_NOT_CONFIGURED: {
268
+ readonly status: 400;
269
+ readonly title: "Global-table introspector not configured";
270
+ };
271
+ readonly KV_NOT_CONFIGURED: {
272
+ readonly status: 400;
273
+ readonly title: "KV introspector not configured";
274
+ };
275
+ readonly MIGRATION_ID_REQUIRED: {
276
+ readonly status: 400;
277
+ readonly title: "Migration id required";
278
+ };
279
+ readonly PITR_UNAVAILABLE: {
280
+ readonly status: 409;
281
+ readonly title: "Point-in-time recovery unavailable";
282
+ };
283
+ readonly SCHEDULER_NOT_CONFIGURED: {
284
+ readonly status: 400;
285
+ readonly title: "Scheduler not configured";
286
+ };
287
+ readonly STORAGE_CHECKSUM_MISMATCH: {
288
+ readonly hint: readonly ["The upload body did not match the declared `expectedSize` or `expectedSha256`, so nothing was written — this check fails closed.", "", "Re-read the bytes from the source export and retry the transfer. A persistent mismatch means the source blob is corrupt or truncated; fix the export rather than bypassing the check."];
289
+ readonly status: 400;
290
+ readonly title: "Storage checksum mismatch";
291
+ };
292
+ readonly STORAGE_DELETE_NOT_CONFIGURED: {
293
+ readonly status: 400;
294
+ readonly title: "Storage delete not configured";
295
+ };
296
+ readonly STORAGE_DOWNLOAD_NOT_CONFIGURED: {
297
+ readonly hint: readonly ["`GET /_lunora/admin/storage/object` needs a `storageDownload` function on the worker. The generated app worker wires it up; a hand-written `createWorker({ ... })` has to pass `(key, opts) => pick(opts?.bucket).download(key)` — forwarding `opts.bucket` to the right bucket, and wrapping rather than passing `createStorage(...).download` itself, whose second parameter is a byte range.", "", "Without it a bucket-backed `lunora backup restore --bucket` cannot read the snapshot. The object is still readable out of band with `wrangler r2 object get`."];
298
+ readonly status: 400;
299
+ readonly title: "Storage download not configured";
300
+ };
301
+ readonly STORAGE_NOT_CONFIGURED: {
302
+ readonly status: 400;
303
+ readonly title: "Storage not configured";
304
+ };
305
+ readonly STORAGE_OBJECT_NOT_FOUND: {
306
+ readonly status: 404;
307
+ readonly title: "Storage object not found";
308
+ };
309
+ readonly STORAGE_UPLOAD_NOT_CONFIGURED: {
310
+ readonly status: 400;
311
+ readonly title: "Storage upload not configured";
312
+ };
313
+ readonly STORAGE_URL_NOT_CONFIGURED: {
314
+ readonly status: 400;
315
+ readonly title: "Storage signed URL not configured";
316
+ };
317
+ readonly VECTORS_NOT_CONFIGURED: {
318
+ readonly status: 400;
319
+ readonly title: "Vector index introspector not configured";
320
+ };
321
+ readonly VECTOR_QUERY_UNSUPPORTED: {
322
+ readonly status: 400;
323
+ readonly title: "Vector index querying not enabled";
324
+ };
325
+ readonly WORKFLOWS_NOT_CONFIGURED: {
326
+ readonly status: 501;
327
+ readonly title: "Workflows not configured";
328
+ };
329
+ /** The auth/security audit read plane (`__lunora_admin__:getAuthAuditLog`). */
330
+ readonly AUTH_AUDIT_NOT_CONFIGURED: {
331
+ readonly status: 400;
332
+ readonly title: "Auth audit reader not configured";
333
+ };
334
+ /**
335
+ * Backend/DB failure reading the auth audit store. The throw site already
336
+ * keeps the message generic and logs the real error server-side only — flagged
337
+ * `internal: true` anyway as the deliberate posture for "a backend read
338
+ * failed", so a future edit that inlines the driver error can't leak it.
339
+ */
340
+ readonly AUTH_AUDIT_READ_FAILED: {
341
+ readonly internal: true;
342
+ readonly status: 500;
343
+ readonly title: "Auth audit read failed";
344
+ };
345
+ /**
346
+ * Cron-job codes. The `*_NOT_STATIC` / `_INVALID` family are codegen
347
+ * build-time diagnostics — like `CODEGEN_DIAGNOSTIC`, they're thrown as plain
348
+ * messages into the CLI/Vite-overlay output, never cross the RPC wire, and are
349
+ * deliberately not `internal` (the message IS the fix). `CRON_JOB_FAILED` is
350
+ * the one runtime-reachable code in this family — its message interpolates
351
+ * binding/function/job names from the deployment, so it is flagged internal.
352
+ */
353
+ readonly CRON_EXPR_INVALID: {
354
+ readonly status: 500;
355
+ readonly title: "Invalid cron expression";
356
+ };
357
+ readonly CRON_EXPR_NOT_STATIC: {
358
+ readonly status: 500;
359
+ readonly title: "Cron expression is not statically analyzable";
360
+ };
361
+ readonly CRON_JOB_FAILED: {
362
+ readonly internal: true;
363
+ readonly status: 500;
364
+ readonly title: "Cron job failed";
365
+ };
366
+ readonly CRON_NAME_NOT_STATIC: {
367
+ readonly status: 500;
368
+ readonly title: "Cron job name is not statically analyzable";
369
+ };
370
+ readonly CRON_NON_STATIC_FN: {
371
+ readonly status: 500;
372
+ readonly title: "Cron function reference is not statically analyzable";
373
+ };
374
+ readonly CRON_NON_STATIC_VALUE: {
375
+ readonly status: 500;
376
+ readonly title: "Cron value is not statically analyzable";
377
+ };
378
+ readonly CRON_SCHEDULE_INVALID: {
379
+ readonly status: 500;
380
+ readonly title: "Invalid cron schedule";
381
+ };
382
+ readonly CRON_SCHEDULE_NOT_STATIC: {
383
+ readonly status: 500;
384
+ readonly title: "Cron schedule is not statically analyzable";
385
+ };
386
+ readonly DUPLICATE_CRON_NAME: {
387
+ readonly status: 500;
388
+ readonly title: "Duplicate cron job name";
389
+ };
390
+ /** More codegen build-time diagnostics — see the cron-family comment above; same reasoning applies. */
391
+ readonly DUPLICATE_AGENT_BINDING: {
392
+ readonly status: 500;
393
+ readonly title: "Duplicate agent binding";
394
+ };
395
+ readonly DUPLICATE_AGENT_CLASS: {
396
+ readonly status: 500;
397
+ readonly title: "Duplicate agent generated class name";
398
+ };
399
+ readonly DUPLICATE_AGENT_NAME: {
400
+ readonly status: 500;
401
+ readonly title: "Duplicate agent name";
402
+ };
403
+ readonly DUPLICATE_MIGRATION_ID: {
404
+ readonly status: 500;
405
+ readonly title: "Duplicate migration id";
406
+ };
407
+ readonly DUPLICATE_QUEUE_BINDING: {
408
+ readonly status: 500;
409
+ readonly title: "Duplicate queue binding";
410
+ };
411
+ readonly DUPLICATE_QUEUE_NAME: {
412
+ readonly status: 500;
413
+ readonly title: "Duplicate queue name";
414
+ };
415
+ readonly DUPLICATE_WORKFLOW_CLASS: {
416
+ readonly status: 500;
417
+ readonly title: "Duplicate workflow generated class name";
418
+ };
419
+ readonly MIGRATION_ID_NOT_STATIC: {
420
+ readonly status: 500;
421
+ readonly title: "Migration id is not statically analyzable";
422
+ };
423
+ readonly NAMESPACE_COLLISION: {
424
+ readonly status: 500;
425
+ readonly title: "Function namespace collision";
426
+ };
427
+ /**
428
+ * `@lunora/runtime`'s dispatch/security-boundary codes — RPC/HTTP entry, not
429
+ * admin-gated. Fixed, non-sensitive messages throughout, so none are `internal`.
430
+ */
431
+ readonly BAD_ROW: {
432
+ readonly status: 400;
433
+ readonly title: "Malformed import row";
434
+ };
435
+ readonly BAD_SUBSCRIPTION_ARGS: {
436
+ readonly status: 400;
437
+ readonly title: "Invalid subscription arguments";
438
+ };
439
+ readonly BATCH_LIMIT_EXCEEDED: {
440
+ readonly status: 400;
441
+ readonly title: "Batch limit exceeded";
442
+ };
443
+ readonly CROSS_SHARD_RANK_UNSUPPORTED: {
444
+ readonly status: 400;
445
+ readonly title: "Cross-shard rank() is unsupported";
446
+ };
447
+ readonly FORBIDDEN_FANOUT: {
448
+ readonly status: 403;
449
+ readonly title: "Fan-out forbidden";
450
+ };
451
+ readonly FORBIDDEN_ORIGIN: {
452
+ readonly status: 403;
453
+ readonly title: "Origin forbidden";
454
+ };
455
+ readonly FORBIDDEN_SHARD: {
456
+ readonly status: 403;
457
+ readonly title: "Shard access forbidden";
458
+ };
459
+ readonly GLOBAL_NOT_CONFIGURED: {
460
+ readonly status: 400;
461
+ readonly title: "Global table import not configured";
462
+ };
463
+ readonly INVALID_INPUT: {
464
+ readonly status: 400;
465
+ readonly title: "Invalid input";
466
+ };
467
+ readonly RATE_LIMITED: {
468
+ readonly status: 429;
469
+ readonly title: "Rate limited";
470
+ };
471
+ /**
472
+ * A read replica could not answer at the freshness the caller required. `421`
473
+ * rather than an error class: it is a ROUTING verdict the runtime turns into
474
+ * one retry against the owner, and a caller never sees it.
475
+ */
476
+ readonly REPLICA_NOT_READY: {
477
+ readonly status: 421;
478
+ readonly title: "Replica not caught up";
479
+ };
480
+ /** A write reached a read replica. Same `421` routing verdict — writes belong to the owner. */
481
+ readonly REPLICA_READ_ONLY: {
482
+ readonly status: 421;
483
+ readonly title: "Replica is read-only";
484
+ };
485
+ /** Thrown by `@lunora/auth` (Turnstile) and `@lunora/ratelimit` — an upstream dependency didn't respond. Fixed, safe message. */
486
+ readonly SERVICE_UNAVAILABLE: {
487
+ readonly status: 503;
488
+ readonly title: "Service unavailable";
489
+ };
490
+ readonly SHAPE_CROSS_SHARD_JOIN: {
491
+ readonly status: 400;
492
+ readonly title: "Shape cross-shard join is unsupported";
493
+ };
494
+ readonly UNAUTHENTICATED: {
495
+ readonly status: 401;
496
+ readonly title: "Unauthenticated";
497
+ };
498
+ readonly UNKNOWN_COLUMN: {
499
+ readonly status: 404;
500
+ readonly title: "Unknown column";
501
+ };
502
+ /**
503
+ * `@lunora/do`'s ShardDO — WebSocket-frame codes and SQLite-in-DO invariants.
504
+ * `NESTED_TRANSACTION` and `SQL_UNAVAILABLE` are "should never happen" state
505
+ * invariants (mirrors `RUN_DEPTH_EXCEEDED`'s posture above): today's message
506
+ * is static and safe, but flagged internal so a future edit that adds
507
+ * diagnostic detail can't accidentally start leaking it.
508
+ */
509
+ readonly EXPIRED: {
510
+ readonly status: 404;
511
+ readonly title: "Session expired";
512
+ };
513
+ readonly NESTED_TRANSACTION: {
514
+ readonly internal: true;
515
+ readonly status: 500;
516
+ readonly title: "Nested transaction";
517
+ };
518
+ readonly OUT_OF_ORDER: {
519
+ readonly status: 409;
520
+ readonly title: "Out-of-order mutation";
521
+ };
522
+ readonly SHAPE_GLOBAL_TOO_LARGE: {
523
+ readonly status: 413;
524
+ readonly title: "Global shape too large";
525
+ };
526
+ readonly SHAPE_NOT_FOUND: {
527
+ readonly status: 404;
528
+ readonly title: "Shape not found";
529
+ };
530
+ readonly SQL_UNAVAILABLE: {
531
+ readonly internal: true;
532
+ readonly status: 500;
533
+ readonly title: "SQL storage unavailable";
534
+ };
535
+ readonly STREAM_INTERRUPTED: {
536
+ readonly status: 503;
537
+ readonly title: "Durable stream interrupted";
538
+ };
539
+ readonly STREAM_TOO_LONG: {
540
+ readonly status: 507;
541
+ readonly title: "Durable stream exceeded its chunk ceiling";
542
+ };
543
+ readonly TOKEN_EXPIRED: {
544
+ readonly status: 401;
545
+ readonly title: "Authentication token expired";
546
+ };
547
+ readonly TOO_MANY_STREAMS: {
548
+ readonly status: 429;
549
+ readonly title: "Too many streams";
550
+ };
551
+ readonly UNKNOWN_ADMIN_OP: {
552
+ readonly status: 404;
553
+ readonly title: "Unknown admin operation";
554
+ };
555
+ /**
556
+ * `@lunora/platform-cloudflare`'s `SocketHost.accept` guard — a caller
557
+ * supplied more accept-time tags (or a longer tag) than Cloudflare's
558
+ * `acceptWebSocket` budget allows once the host's own identity tag is
559
+ * reserved. Caller-actionable and safe (names counts, not internals) —
560
+ * not `internal`.
561
+ */
562
+ readonly SOCKET_TAG_BUDGET_EXCEEDED: {
563
+ readonly status: 400;
564
+ readonly title: "Socket tag budget exceeded";
565
+ };
566
+ /**
567
+ * `@lunora/shard-engine`'s relay hub (cross-shard shape relay coordination).
568
+ * Mirrors `SHARD_ERROR`/`SHARD_UNAVAILABLE` above: operational status for an
569
+ * app's own relay topology, not a secret — not `internal`.
570
+ */
571
+ readonly RELAY_CANNOT_SEED: {
572
+ readonly status: 500;
573
+ readonly title: "Relay cannot seed";
574
+ };
575
+ readonly RELAY_MISCONFIGURED: {
576
+ readonly status: 500;
577
+ readonly title: "Relay misconfigured";
578
+ };
579
+ readonly RELAY_SEED_FAILED: {
580
+ readonly status: 502;
581
+ readonly title: "Relay seed failed";
582
+ };
583
+ /**
584
+ * A worker option required by the request path is absent (a deploy-config
585
+ * gap, not a caller error) — the fixed message names the missing option, so
586
+ * it's actionable and echoed. `MISCONFIGURED` is the one exception: its
587
+ * message interpolates the caller-supplied `functionPath`, and it's the code
588
+ * this plan's audit found live-leaking (`create-worker.ts`'s x402 gate).
589
+ */
590
+ readonly MISCONFIGURED: {
591
+ readonly internal: true;
592
+ readonly status: 500;
593
+ readonly title: "Worker misconfigured";
594
+ };
595
+ /** `@lunora/nuxt`'s Nitro bridge: the request carried no Cloudflare bindings. Fixed, safe message. */
596
+ readonly LUNORA_RUNTIME_UNAVAILABLE: {
597
+ readonly status: 500;
598
+ readonly title: "Lunora runtime unavailable";
599
+ };
600
+ /**
601
+ * `@lunora/replica`'s event-log Durable Object: generic request-handler
602
+ * catch-all, mirroring `INTERNAL`/`INTERNAL_SERVER_ERROR`/`RPC_FAILED` above
603
+ * — the real error is logged server-side only, never in this code's message.
604
+ */
605
+ readonly INTERNAL_ERROR: {
606
+ readonly internal: true;
607
+ readonly status: 500;
608
+ readonly title: "Internal error";
609
+ };
610
+ /**
611
+ * Client-SDK-only codes (`@lunora/client`), thrown locally in the browser/app
612
+ * process rather than by the server — `internal`'s wire-redaction semantics
613
+ * don't apply the same way here, since the "wire" is the app's own code
614
+ * catching its own client's exception. Kept in the catalog for the client's
615
+ * `code`-discrimination union and Studio/CLI rendering consistency.
616
+ */
617
+ readonly BROWSER_TIMEOUT: {
618
+ readonly status: 504;
619
+ readonly title: "Browser operation timed out";
620
+ };
621
+ readonly CLIENT_CLOSED: {
622
+ readonly status: 400;
623
+ readonly title: "Client is closed";
624
+ };
625
+ readonly HTTP_STREAM_BAD_CHUNK: {
626
+ readonly status: 502;
627
+ readonly title: "Malformed HTTP stream chunk";
628
+ };
629
+ readonly HTTP_STREAM_INTERRUPTED: {
630
+ readonly status: 502;
631
+ readonly title: "HTTP stream interrupted";
632
+ };
633
+ readonly HTTP_STREAM_MISSING_PARAM: {
634
+ readonly status: 400;
635
+ readonly title: "HTTP stream missing path parameter";
636
+ };
637
+ readonly HTTP_STREAM_NO_BODY: {
638
+ readonly status: 502;
639
+ readonly title: "HTTP stream response has no body";
640
+ };
641
+ readonly HTTP_STREAM_STATUS: {
642
+ readonly status: 502;
643
+ readonly title: "HTTP stream request failed";
644
+ };
645
+ readonly HTTP_STREAM_TRANSPORT: {
646
+ readonly status: 502;
647
+ readonly title: "HTTP stream transport error";
648
+ };
649
+ readonly STREAM_BACKPRESSURE: {
650
+ readonly status: 429;
651
+ readonly title: "Stream backpressure";
652
+ };
653
+ readonly STREAM_DISCONNECTED: {
654
+ readonly status: 503;
655
+ readonly title: "Stream disconnected";
656
+ };
657
+ readonly STREAM_QUEUE_OVERFLOW: {
658
+ readonly status: 429;
659
+ readonly title: "Stream queue overflow";
660
+ };
661
+ /** `@lunora/db`'s offline outbox: a queued write targeted a collection removed/renamed in a later deploy. */
662
+ readonly UNKNOWN_MUTATION_FN: {
663
+ readonly status: 404;
664
+ readonly title: "Unknown mutation function";
665
+ };
179
666
  };
180
667
  /** A well-known Lunora error code (a key of {@link ERROR_CATALOG}). */
181
668
  type LunoraErrorCode = keyof typeof ERROR_CATALOG;
182
669
  /**
183
- * True when `code` is an internal/redacted code — an internal failure or
184
- * unhandled invariant whose `message` must NOT cross the wire (it may carry SQL
185
- * fragments, file paths, or internal identifiers). Derived from the catalog's
186
- * `internal` flag so the redaction posture stays in one place (the table).
187
- * Throwing a `LunoraError` with any non-internal code is the author's vouch that
188
- * its message is client-safe; an unknown/unregistered code is treated as safe.
189
- */
670
+ * True when `code` is an internal/redacted code — an internal failure or
671
+ * unhandled invariant whose `message` must NOT cross the wire (it may carry SQL
672
+ * fragments, file paths, or internal identifiers). Derived from the catalog's
673
+ * `internal` flag so the redaction posture stays in one place (the table).
674
+ * Throwing a `LunoraError` with any non-internal code is the author's vouch that
675
+ * its message is client-safe; an unknown/unregistered code is treated as safe.
676
+ */
190
677
  declare const isInternalCode: (code: string) => boolean;
191
678
  /**
192
- * A message-matched solution for errors that reach a consumer without a `code`
193
- * — chiefly `@lunora/codegen` build errors, which are thrown as plain messages
194
- * into generated code (and flattened to `{ message }` by the Vite overlay), so
195
- * the message text is the only stable join key. Ordered most- to least-specific;
196
- * the first matching rule wins.
197
- */
679
+ * A message-matched solution for errors that reach a consumer without a `code`
680
+ * — chiefly `@lunora/codegen` build errors, which are thrown as plain messages
681
+ * into generated code (and flattened to `{ message }` by the Vite overlay), so
682
+ * the message text is the only stable join key. Ordered most- to least-specific;
683
+ * the first matching rule wins.
684
+ */
198
685
  interface Solution {
199
686
  /** Markdown body shown under the header. */
200
687
  body: string;
@@ -209,27 +696,92 @@ interface SolutionRule extends Solution {
209
696
  test: (message: string) => boolean;
210
697
  }
211
698
  /**
212
- * Message-matched solutions (migrated verbatim from the former
213
- * `@lunora/codegen` solutions table). Re-exported by `@lunora/codegen` as
214
- * `LUNORA_SOLUTION_RULES` for backward compatibility.
215
- */
699
+ * Message-matched solutions (migrated verbatim from the former
700
+ * `@lunora/codegen` solutions table). Re-exported by `@lunora/codegen` as
701
+ * `LUNORA_SOLUTION_RULES` for backward compatibility.
702
+ */
216
703
  declare const MESSAGE_SOLUTIONS: ReadonlyArray<SolutionRule>;
217
704
  /**
218
- * Flatten a Markdown hint to plain text for a terminal / non-Markdown surface:
219
- * drop code-fence markers and strip inline `**bold**` / `` `code` `` emphasis.
220
- * Shared by the CLI renderer and the Studio `ErrorAlert` so the two can't drift.
221
- */
705
+ * One documented Cloudflare **platform** error an edge/origin (5xx) or
706
+ * Cloudflare-service (1xxx) failure surfaced in an error *message* rather than
707
+ * thrown by Lunora as a coded `LunoraError`. These reach a Lunora app as
708
+ * plain text: a Worker that fetches a Cloudflare-fronted origin sees `Error 522`,
709
+ * a deploy that throws surfaces as `Error 1101`, and so on. The fields are the
710
+ * curated facts a grounded explainer elaborates on — never invents beyond.
711
+ */
712
+ interface CloudflarePlatformError {
713
+ /** Documented likely causes (a short, comma-joined clause). */
714
+ causes: string;
715
+ /** The numeric Cloudflare error code, as it appears in the message (e.g. `"522"`, `"1101"`). */
716
+ code: string;
717
+ /** Canonical Cloudflare support-docs URL for this error's family. */
718
+ docsUrl: string;
719
+ /** Which docs family the code belongs to — shown in the "see docs" line. */
720
+ family: "1xxx" | "5xx";
721
+ /** The documented remediation. */
722
+ fix: string;
723
+ /** One-line summary of what the code means. */
724
+ summary: string;
725
+ /** Cloudflare's short name for the code (e.g. `"Connection timed out"`). */
726
+ title: string;
727
+ }
728
+ /**
729
+ * The curated Cloudflare platform-error table. Sourced from Cloudflare's official
730
+ * support docs — the codes surfaced to app authors on Workers/DO deployments (the
731
+ * origin-connection 52x family and the Worker/DNS/security 1xxx family). `1101`
732
+ * (a Worker threw) and `1102` (a Worker exceeded CPU) are the most Lunora-relevant.
733
+ */
734
+ declare const CLOUDFLARE_PLATFORM_ERRORS: ReadonlyArray<CloudflarePlatformError>;
735
+ /**
736
+ * Recognize a Cloudflare platform-error {@link CloudflarePlatformError} in a raw
737
+ * error message, conservatively: the message must carry Cloudflare's own
738
+ * `Error <code>` phrasing, or mention `cloudflare` alongside the standalone
739
+ * code. That keeps a bare number (`expected 520 items`) from false-matching a 5xx
740
+ * code, at the cost of missing a context-free code — the safe trade for a
741
+ * grounded hint. Returns the matched code's {@link Solution}, or `undefined`.
742
+ *
743
+ * Matching runs in two passes, strongest first: Cloudflare's own `Error <code>`
744
+ * phrasing is unambiguous, so it must win over the weaker "mentions cloudflare
745
+ * near some number" heuristic regardless of table order. A single pass let a weak
746
+ * match on an earlier entry beat an explicit match on a later one — `"Cloudflare
747
+ * Error 1102: exceeded after 524 ms"` resolved to 524, and that wrong grounded
748
+ * fix is exactly what the explainer prompt is built from.
749
+ */
750
+ declare const findCloudflarePlatformSolution: (message: string) => Solution | undefined;
751
+ /**
752
+ * Flatten a Markdown hint to plain text for a terminal / non-Markdown surface:
753
+ * drop code-fence markers and strip inline `**bold**` / `` `code` `` emphasis.
754
+ * Shared by the CLI renderer and the Studio `ErrorAlert` so the two can't drift.
755
+ */
222
756
  declare const flattenHint: (hint: ErrorHint) => string;
223
757
  /**
224
- * Find the first message-matched {@link Solution} for `message`, or `undefined`
225
- * if none recognize it. Re-exported by `@lunora/codegen` as `findLunoraSolution`.
226
- */
758
+ * Find the first message-matched {@link Solution} for `message`, or `undefined`
759
+ * if none recognize it. Re-exported by `@lunora/codegen` as `findLunoraSolution`.
760
+ */
227
761
  declare const findSolutionByMessage: (message: string) => Solution | undefined;
228
762
  /**
229
- * Resolve an actionable hint for an error: prefer a hint carried on the error
230
- * (or its `code`'s catalog entry), then fall back to a message match. Returns
231
- * `undefined` when nothing recognizes it.
232
- */
763
+ * Find a solution for `message` across BOTH Lunora's own rules and the curated
764
+ * Cloudflare platform-error table the lookup the Studio Issues panel and the
765
+ * `explainIssue` grounding use.
766
+ *
767
+ * Deliberately separate from {@link findSolutionByMessage} rather than folded into
768
+ * it. That function is on `resolveHint`, and therefore on `toErrorBody` — the
769
+ * envelope builder for every failed request. Most `ERROR_CATALOG` entries
770
+ * carry no `hint`, so folding the platform table in there meant an ordinary
771
+ * `BAD_REQUEST` whose message merely mentioned "cloudflare" near a number shipped
772
+ * zone-configuration guidance ("review the zone's Firewall/WAF and IP Access
773
+ * Rules") to unauthenticated browsers. The same fold put the table on the CLI
774
+ * renderer and the Vite overlay, and on `toErrorBody`'s hot path.
775
+ *
776
+ * Platform errors are operator-facing context for an already-persisted Issue, so
777
+ * the operator-facing surfaces opt in here and the wire path stays Lunora-only.
778
+ */
779
+ declare const findIssueSolution: (message: string) => Solution | undefined;
780
+ /**
781
+ * Resolve an actionable hint for an error: prefer a hint carried on the error
782
+ * (or its `code`'s catalog entry), then fall back to a message match. Returns
783
+ * `undefined` when nothing recognizes it.
784
+ */
233
785
  declare const resolveHint: (input: {
234
786
  code?: string;
235
787
  hint?: ErrorHint;
@@ -261,16 +813,16 @@ interface LunoraErrorOptions {
261
813
  title?: string;
262
814
  }
263
815
  /**
264
- * A code string: a well-known {@link LunoraErrorCode} (with autocomplete) or any
265
- * package-specific code not yet in the catalog.
266
- */
816
+ * A code string: a well-known {@link LunoraErrorCode} (with autocomplete) or any
817
+ * package-specific code not yet in the catalog.
818
+ */
267
819
  type LunoraErrorCodeInput = LunoraErrorCode | (string & {});
268
820
  declare class LunoraError extends Error {
269
821
  /**
270
- * Discriminator recognised by `@visulima/error`'s `renderError`/`isVisulimaError`
271
- * (`error.type === "VisulimaError"`), so a `LunoraError` renders like a native
272
- * `VisulimaError` — hint and all.
273
- */
822
+ * Discriminator recognised by `@visulima/error`'s `renderError`/`isVisulimaError`
823
+ * (`error.type === "VisulimaError"`), so a `LunoraError` renders like a native
824
+ * `VisulimaError` — hint and all.
825
+ */
274
826
  readonly type = "VisulimaError";
275
827
  /** Actionable fix (Markdown), rendered by the CLI/overlay/Studio. */
276
828
  readonly hint: ErrorHint | undefined;
@@ -278,7 +830,7 @@ declare class LunoraError extends Error {
278
830
  readonly title: string | undefined;
279
831
  /** Source location, when known (mirrors `VisulimaError.loc`). */
280
832
  readonly loc: ErrorLocation | undefined;
281
- /** Machine-readable reason, keyed into {@link ERROR_CATALOG}. */
833
+ /** Machine-readable reason, keyed into `ERROR_CATALOG`. */
282
834
  readonly code: string;
283
835
  /** HTTP/RPC status for the transport mappers. */
284
836
  readonly status: number;
@@ -295,8 +847,15 @@ interface LunoraErrorLike extends Error {
295
847
  docsUrl?: string;
296
848
  hint?: ErrorHint;
297
849
  status: number;
850
+ /** Wire brand that distinguishes real `LunoraError`s from foreign errors. */
851
+ type: "VisulimaError";
298
852
  }
299
- /** True when `error` carries the Lunora transport shape (string `code` + numeric `status`). */
853
+ /**
854
+ * True when `error` carries the Lunora transport shape (string `code` + numeric
855
+ * `status` + the `VisulimaError` brand). The `type` brand is what distinguishes
856
+ * a real `LunoraError` (or its wire-decoded twin) from a foreign error that
857
+ * happens to carry `code`/`status` — see plan 119 for the full rationale.
858
+ */
300
859
  declare const isLunoraError: (error: unknown) => error is LunoraErrorLike;
301
860
  /** Throw an `INTERNAL` {@link LunoraError} when `condition` is falsy. */
302
861
  declare const invariant: (condition: unknown, message: string) => asserts condition;
@@ -312,9 +871,9 @@ interface ErrorBody {
312
871
  }
313
872
  interface ToErrorBodyOptions {
314
873
  /**
315
- * Wire-encode a `LunoraError`'s structured `data` for the client (so a
316
- * `bigint`/`bytes` inside it survives). Omit to drop `data` from the body.
317
- */
874
+ * Wire-encode a `LunoraError`'s structured `data` for the client (so a
875
+ * `bigint`/`bytes` inside it survives). Omit to drop `data` from the body.
876
+ */
318
877
  encodeData?: (data: unknown) => unknown;
319
878
  /** Code for an unrecognized (non-`LunoraError`) throw. Default `"INTERNAL"`. */
320
879
  fallbackCode?: string;
@@ -329,12 +888,12 @@ interface ToErrorBodyResult {
329
888
  status: number;
330
889
  }
331
890
  /**
332
- * Turn a thrown value into an {@link ErrorBody} + status, applying the redaction
333
- * invariant. A `LunoraError` with a non-internal code is echoed with its
334
- * `message`, resolved `hint`, `docsUrl`, and (when `encodeData` is given) its
335
- * `data`. An internal-coded `LunoraError` keeps its `code`/`status` but its
336
- * message is replaced with `redactedMessage`. Anything else becomes a generic
337
- * `fallbackCode`/500. When `redacted` is `true`, log the raw error server-side.
338
- */
891
+ * Turn a thrown value into an {@link ErrorBody} + status, applying the redaction
892
+ * invariant. A `LunoraError` with a non-internal code is echoed with its
893
+ * `message`, resolved `hint`, `docsUrl`, and (when `encodeData` is given) its
894
+ * `data`. An internal-coded `LunoraError` keeps its `code`/`status` but its
895
+ * message is replaced with `redactedMessage`. Anything else becomes a generic
896
+ * `fallbackCode`/500. When `redacted` is `true`, log the raw error server-side.
897
+ */
339
898
  declare const toErrorBody: (error: unknown, options?: ToErrorBodyOptions) => ToErrorBodyResult;
340
- export { ERROR_CATALOG, type ErrorBody, type ErrorCatalogEntry, type ErrorHint, type ErrorLocation, LunoraError, type LunoraErrorCode, type LunoraErrorCodeInput, type LunoraErrorLike, type LunoraErrorOptions, MESSAGE_SOLUTIONS, type Solution, type SolutionRule, type ToErrorBodyOptions, type ToErrorBodyResult, findSolutionByMessage, flattenHint, invariant, isInternalCode, isLunoraError, resolveHint, toErrorBody, unreachable };
899
+ export { CLOUDFLARE_PLATFORM_ERRORS, type CloudflarePlatformError, ERROR_CATALOG, type ErrorBody, type ErrorCatalogEntry, type ErrorHint, type ErrorLocation, LunoraError, type LunoraErrorCode, type LunoraErrorCodeInput, type LunoraErrorLike, type LunoraErrorOptions, MESSAGE_SOLUTIONS, type Solution, type SolutionRule, type ToErrorBodyOptions, type ToErrorBodyResult, findCloudflarePlatformSolution, findIssueSolution, findSolutionByMessage, flattenHint, invariant, isInternalCode, isLunoraError, resolveHint, toErrorBody, unreachable };