@lunora/errors 1.0.0-alpha.5 → 1.0.0-alpha.6
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 +83 -80
- package/dist/index.d.ts +83 -80
- package/dist/index.mjs +4 -4
- package/dist/packem_shared/{ERROR_CATALOG-pJvm6SQP.mjs → ERROR_CATALOG-DaTEqgq6.mjs} +1 -1
- package/dist/packem_shared/{LunoraError-Cdb2-Hda.mjs → LunoraError-DQkqKSaw.mjs} +1 -1
- package/dist/packem_shared/{invariant-HhlkSkbP.mjs → invariant-DFMi4YKZ.mjs} +1 -1
- package/dist/packem_shared/{toErrorBody-BXvKCSrv.mjs → toErrorBody-BbkgBfL5.mjs} +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
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
|
-
*/
|
|
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
14
|
/** Markdown hint: a single string or an array of lines. Shape matches `@visulima/error`'s `hint`. */
|
|
15
|
-
type ErrorHint = string | string[];
|
|
15
|
+
type ErrorHint = string | readonly string[];
|
|
16
16
|
/** A catalog entry: the fixed metadata for one error `code`. */
|
|
17
17
|
interface ErrorCatalogEntry {
|
|
18
18
|
/** Optional URL to deeper docs for this error. */
|
|
@@ -20,11 +20,11 @@ interface ErrorCatalogEntry {
|
|
|
20
20
|
/** Optional actionable fix, authored as Markdown (rendered by CLI/overlay/Studio). */
|
|
21
21
|
hint?: ErrorHint;
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
*/
|
|
28
28
|
internal?: boolean;
|
|
29
29
|
/** HTTP/RPC status this code maps to on the wire. */
|
|
30
30
|
status: number;
|
|
@@ -32,10 +32,10 @@ interface ErrorCatalogEntry {
|
|
|
32
32
|
title: string;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
39
39
|
declare const ERROR_CATALOG: {
|
|
40
40
|
readonly BAD_REQUEST: {
|
|
41
41
|
readonly status: 400;
|
|
@@ -78,7 +78,8 @@ declare const ERROR_CATALOG: {
|
|
|
78
78
|
readonly NOT_IMPLEMENTED: {
|
|
79
79
|
readonly status: 501;
|
|
80
80
|
readonly title: "Not implemented";
|
|
81
|
-
};
|
|
81
|
+
};
|
|
82
|
+
/** RPC/REST dispatch codes emitted by the runtime + Durable Object router. */
|
|
82
83
|
readonly FUNCTION_NOT_FOUND: {
|
|
83
84
|
readonly status: 404;
|
|
84
85
|
readonly title: "Function not found";
|
|
@@ -90,7 +91,8 @@ declare const ERROR_CATALOG: {
|
|
|
90
91
|
readonly PAYLOAD_TOO_LARGE: {
|
|
91
92
|
readonly status: 413;
|
|
92
93
|
readonly title: "Payload too large";
|
|
93
|
-
};
|
|
94
|
+
};
|
|
95
|
+
/** Free-form internal failure — redacted to a generic message on the wire. */
|
|
94
96
|
readonly INTERNAL: {
|
|
95
97
|
readonly internal: true;
|
|
96
98
|
readonly status: 500;
|
|
@@ -153,7 +155,8 @@ declare const ERROR_CATALOG: {
|
|
|
153
155
|
readonly OFFLINE_IDENTITY_CHANGED: {
|
|
154
156
|
readonly status: 409;
|
|
155
157
|
readonly title: "Offline identity changed";
|
|
156
|
-
};
|
|
158
|
+
};
|
|
159
|
+
/** Package-specific codes. Build-time-only — never cross the RPC wire, so deliberately not `internal`. */
|
|
157
160
|
readonly CODEGEN_DIAGNOSTIC: {
|
|
158
161
|
readonly status: 500;
|
|
159
162
|
readonly title: "Codegen diagnostic";
|
|
@@ -176,11 +179,11 @@ declare const ERROR_CATALOG: {
|
|
|
176
179
|
readonly title: "Auth headers missing";
|
|
177
180
|
};
|
|
178
181
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
* Upstream Cloudflare API failures surfaced from an action. The message
|
|
183
|
+
* carries the upstream response body (Cloudflare's own error text — trusted
|
|
184
|
+
* infra, not user input), so it is echoed rather than redacted. `status`
|
|
185
|
+
* here is a fallback; each throw passes the actual upstream HTTP status.
|
|
186
|
+
*/
|
|
184
187
|
readonly ANALYTICS_SQL_ERROR: {
|
|
185
188
|
readonly status: 502;
|
|
186
189
|
readonly title: "Analytics Engine SQL API error";
|
|
@@ -197,21 +200,21 @@ declare const ERROR_CATALOG: {
|
|
|
197
200
|
/** A well-known Lunora error code (a key of {@link ERROR_CATALOG}). */
|
|
198
201
|
type LunoraErrorCode = keyof typeof ERROR_CATALOG;
|
|
199
202
|
/**
|
|
200
|
-
* True when `code` is an internal/redacted code — an internal failure or
|
|
201
|
-
* unhandled invariant whose `message` must NOT cross the wire (it may carry SQL
|
|
202
|
-
* fragments, file paths, or internal identifiers). Derived from the catalog's
|
|
203
|
-
* `internal` flag so the redaction posture stays in one place (the table).
|
|
204
|
-
* Throwing a `LunoraError` with any non-internal code is the author's vouch that
|
|
205
|
-
* its message is client-safe; an unknown/unregistered code is treated as safe.
|
|
206
|
-
*/
|
|
203
|
+
* True when `code` is an internal/redacted code — an internal failure or
|
|
204
|
+
* unhandled invariant whose `message` must NOT cross the wire (it may carry SQL
|
|
205
|
+
* fragments, file paths, or internal identifiers). Derived from the catalog's
|
|
206
|
+
* `internal` flag so the redaction posture stays in one place (the table).
|
|
207
|
+
* Throwing a `LunoraError` with any non-internal code is the author's vouch that
|
|
208
|
+
* its message is client-safe; an unknown/unregistered code is treated as safe.
|
|
209
|
+
*/
|
|
207
210
|
declare const isInternalCode: (code: string) => boolean;
|
|
208
211
|
/**
|
|
209
|
-
* A message-matched solution for errors that reach a consumer without a `code`
|
|
210
|
-
* — chiefly `@lunora/codegen` build errors, which are thrown as plain messages
|
|
211
|
-
* into generated code (and flattened to `{ message }` by the Vite overlay), so
|
|
212
|
-
* the message text is the only stable join key. Ordered most- to least-specific;
|
|
213
|
-
* the first matching rule wins.
|
|
214
|
-
*/
|
|
212
|
+
* A message-matched solution for errors that reach a consumer without a `code`
|
|
213
|
+
* — chiefly `@lunora/codegen` build errors, which are thrown as plain messages
|
|
214
|
+
* into generated code (and flattened to `{ message }` by the Vite overlay), so
|
|
215
|
+
* the message text is the only stable join key. Ordered most- to least-specific;
|
|
216
|
+
* the first matching rule wins.
|
|
217
|
+
*/
|
|
215
218
|
interface Solution {
|
|
216
219
|
/** Markdown body shown under the header. */
|
|
217
220
|
body: string;
|
|
@@ -226,27 +229,27 @@ interface SolutionRule extends Solution {
|
|
|
226
229
|
test: (message: string) => boolean;
|
|
227
230
|
}
|
|
228
231
|
/**
|
|
229
|
-
* Message-matched solutions (migrated verbatim from the former
|
|
230
|
-
* `@lunora/codegen` solutions table). Re-exported by `@lunora/codegen` as
|
|
231
|
-
* `LUNORA_SOLUTION_RULES` for backward compatibility.
|
|
232
|
-
*/
|
|
232
|
+
* Message-matched solutions (migrated verbatim from the former
|
|
233
|
+
* `@lunora/codegen` solutions table). Re-exported by `@lunora/codegen` as
|
|
234
|
+
* `LUNORA_SOLUTION_RULES` for backward compatibility.
|
|
235
|
+
*/
|
|
233
236
|
declare const MESSAGE_SOLUTIONS: ReadonlyArray<SolutionRule>;
|
|
234
237
|
/**
|
|
235
|
-
* Flatten a Markdown hint to plain text for a terminal / non-Markdown surface:
|
|
236
|
-
* drop code-fence markers and strip inline `**bold**` / `` `code` `` emphasis.
|
|
237
|
-
* Shared by the CLI renderer and the Studio `ErrorAlert` so the two can't drift.
|
|
238
|
-
*/
|
|
238
|
+
* Flatten a Markdown hint to plain text for a terminal / non-Markdown surface:
|
|
239
|
+
* drop code-fence markers and strip inline `**bold**` / `` `code` `` emphasis.
|
|
240
|
+
* Shared by the CLI renderer and the Studio `ErrorAlert` so the two can't drift.
|
|
241
|
+
*/
|
|
239
242
|
declare const flattenHint: (hint: ErrorHint) => string;
|
|
240
243
|
/**
|
|
241
|
-
* Find the first message-matched {@link Solution} for `message`, or `undefined`
|
|
242
|
-
* if none recognize it. Re-exported by `@lunora/codegen` as `findLunoraSolution`.
|
|
243
|
-
*/
|
|
244
|
+
* Find the first message-matched {@link Solution} for `message`, or `undefined`
|
|
245
|
+
* if none recognize it. Re-exported by `@lunora/codegen` as `findLunoraSolution`.
|
|
246
|
+
*/
|
|
244
247
|
declare const findSolutionByMessage: (message: string) => Solution | undefined;
|
|
245
248
|
/**
|
|
246
|
-
* Resolve an actionable hint for an error: prefer a hint carried on the error
|
|
247
|
-
* (or its `code`'s catalog entry), then fall back to a message match. Returns
|
|
248
|
-
* `undefined` when nothing recognizes it.
|
|
249
|
-
*/
|
|
249
|
+
* Resolve an actionable hint for an error: prefer a hint carried on the error
|
|
250
|
+
* (or its `code`'s catalog entry), then fall back to a message match. Returns
|
|
251
|
+
* `undefined` when nothing recognizes it.
|
|
252
|
+
*/
|
|
250
253
|
declare const resolveHint: (input: {
|
|
251
254
|
code?: string;
|
|
252
255
|
hint?: ErrorHint;
|
|
@@ -278,16 +281,16 @@ interface LunoraErrorOptions {
|
|
|
278
281
|
title?: string;
|
|
279
282
|
}
|
|
280
283
|
/**
|
|
281
|
-
* A code string: a well-known {@link LunoraErrorCode} (with autocomplete) or any
|
|
282
|
-
* package-specific code not yet in the catalog.
|
|
283
|
-
*/
|
|
284
|
+
* A code string: a well-known {@link LunoraErrorCode} (with autocomplete) or any
|
|
285
|
+
* package-specific code not yet in the catalog.
|
|
286
|
+
*/
|
|
284
287
|
type LunoraErrorCodeInput = LunoraErrorCode | (string & {});
|
|
285
288
|
declare class LunoraError extends Error {
|
|
286
289
|
/**
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
* Discriminator recognised by `@visulima/error`'s `renderError`/`isVisulimaError`
|
|
291
|
+
* (`error.type === "VisulimaError"`), so a `LunoraError` renders like a native
|
|
292
|
+
* `VisulimaError` — hint and all.
|
|
293
|
+
*/
|
|
291
294
|
readonly type = "VisulimaError";
|
|
292
295
|
/** Actionable fix (Markdown), rendered by the CLI/overlay/Studio. */
|
|
293
296
|
readonly hint: ErrorHint | undefined;
|
|
@@ -316,11 +319,11 @@ interface LunoraErrorLike extends Error {
|
|
|
316
319
|
type: "VisulimaError";
|
|
317
320
|
}
|
|
318
321
|
/**
|
|
319
|
-
* True when `error` carries the Lunora transport shape (string `code` + numeric
|
|
320
|
-
* `status` + the `VisulimaError` brand). The `type` brand is what distinguishes
|
|
321
|
-
* a real `LunoraError` (or its wire-decoded twin) from a foreign error that
|
|
322
|
-
* happens to carry `code`/`status` — see plan 119 for the full rationale.
|
|
323
|
-
*/
|
|
322
|
+
* True when `error` carries the Lunora transport shape (string `code` + numeric
|
|
323
|
+
* `status` + the `VisulimaError` brand). The `type` brand is what distinguishes
|
|
324
|
+
* a real `LunoraError` (or its wire-decoded twin) from a foreign error that
|
|
325
|
+
* happens to carry `code`/`status` — see plan 119 for the full rationale.
|
|
326
|
+
*/
|
|
324
327
|
declare const isLunoraError: (error: unknown) => error is LunoraErrorLike;
|
|
325
328
|
/** Throw an `INTERNAL` {@link LunoraError} when `condition` is falsy. */
|
|
326
329
|
declare const invariant: (condition: unknown, message: string) => asserts condition;
|
|
@@ -336,9 +339,9 @@ interface ErrorBody {
|
|
|
336
339
|
}
|
|
337
340
|
interface ToErrorBodyOptions {
|
|
338
341
|
/**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
* Wire-encode a `LunoraError`'s structured `data` for the client (so a
|
|
343
|
+
* `bigint`/`bytes` inside it survives). Omit to drop `data` from the body.
|
|
344
|
+
*/
|
|
342
345
|
encodeData?: (data: unknown) => unknown;
|
|
343
346
|
/** Code for an unrecognized (non-`LunoraError`) throw. Default `"INTERNAL"`. */
|
|
344
347
|
fallbackCode?: string;
|
|
@@ -353,12 +356,12 @@ interface ToErrorBodyResult {
|
|
|
353
356
|
status: number;
|
|
354
357
|
}
|
|
355
358
|
/**
|
|
356
|
-
* Turn a thrown value into an {@link ErrorBody} + status, applying the redaction
|
|
357
|
-
* invariant. A `LunoraError` with a non-internal code is echoed with its
|
|
358
|
-
* `message`, resolved `hint`, `docsUrl`, and (when `encodeData` is given) its
|
|
359
|
-
* `data`. An internal-coded `LunoraError` keeps its `code`/`status` but its
|
|
360
|
-
* message is replaced with `redactedMessage`. Anything else becomes a generic
|
|
361
|
-
* `fallbackCode`/500. When `redacted` is `true`, log the raw error server-side.
|
|
362
|
-
*/
|
|
359
|
+
* Turn a thrown value into an {@link ErrorBody} + status, applying the redaction
|
|
360
|
+
* invariant. A `LunoraError` with a non-internal code is echoed with its
|
|
361
|
+
* `message`, resolved `hint`, `docsUrl`, and (when `encodeData` is given) its
|
|
362
|
+
* `data`. An internal-coded `LunoraError` keeps its `code`/`status` but its
|
|
363
|
+
* message is replaced with `redactedMessage`. Anything else becomes a generic
|
|
364
|
+
* `fallbackCode`/500. When `redacted` is `true`, log the raw error server-side.
|
|
365
|
+
*/
|
|
363
366
|
declare const toErrorBody: (error: unknown, options?: ToErrorBodyOptions) => ToErrorBodyResult;
|
|
364
367
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
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
|
-
*/
|
|
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
14
|
/** Markdown hint: a single string or an array of lines. Shape matches `@visulima/error`'s `hint`. */
|
|
15
|
-
type ErrorHint = string | string[];
|
|
15
|
+
type ErrorHint = string | readonly string[];
|
|
16
16
|
/** A catalog entry: the fixed metadata for one error `code`. */
|
|
17
17
|
interface ErrorCatalogEntry {
|
|
18
18
|
/** Optional URL to deeper docs for this error. */
|
|
@@ -20,11 +20,11 @@ interface ErrorCatalogEntry {
|
|
|
20
20
|
/** Optional actionable fix, authored as Markdown (rendered by CLI/overlay/Studio). */
|
|
21
21
|
hint?: ErrorHint;
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
*/
|
|
28
28
|
internal?: boolean;
|
|
29
29
|
/** HTTP/RPC status this code maps to on the wire. */
|
|
30
30
|
status: number;
|
|
@@ -32,10 +32,10 @@ interface ErrorCatalogEntry {
|
|
|
32
32
|
title: string;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
39
39
|
declare const ERROR_CATALOG: {
|
|
40
40
|
readonly BAD_REQUEST: {
|
|
41
41
|
readonly status: 400;
|
|
@@ -78,7 +78,8 @@ declare const ERROR_CATALOG: {
|
|
|
78
78
|
readonly NOT_IMPLEMENTED: {
|
|
79
79
|
readonly status: 501;
|
|
80
80
|
readonly title: "Not implemented";
|
|
81
|
-
};
|
|
81
|
+
};
|
|
82
|
+
/** RPC/REST dispatch codes emitted by the runtime + Durable Object router. */
|
|
82
83
|
readonly FUNCTION_NOT_FOUND: {
|
|
83
84
|
readonly status: 404;
|
|
84
85
|
readonly title: "Function not found";
|
|
@@ -90,7 +91,8 @@ declare const ERROR_CATALOG: {
|
|
|
90
91
|
readonly PAYLOAD_TOO_LARGE: {
|
|
91
92
|
readonly status: 413;
|
|
92
93
|
readonly title: "Payload too large";
|
|
93
|
-
};
|
|
94
|
+
};
|
|
95
|
+
/** Free-form internal failure — redacted to a generic message on the wire. */
|
|
94
96
|
readonly INTERNAL: {
|
|
95
97
|
readonly internal: true;
|
|
96
98
|
readonly status: 500;
|
|
@@ -153,7 +155,8 @@ declare const ERROR_CATALOG: {
|
|
|
153
155
|
readonly OFFLINE_IDENTITY_CHANGED: {
|
|
154
156
|
readonly status: 409;
|
|
155
157
|
readonly title: "Offline identity changed";
|
|
156
|
-
};
|
|
158
|
+
};
|
|
159
|
+
/** Package-specific codes. Build-time-only — never cross the RPC wire, so deliberately not `internal`. */
|
|
157
160
|
readonly CODEGEN_DIAGNOSTIC: {
|
|
158
161
|
readonly status: 500;
|
|
159
162
|
readonly title: "Codegen diagnostic";
|
|
@@ -176,11 +179,11 @@ declare const ERROR_CATALOG: {
|
|
|
176
179
|
readonly title: "Auth headers missing";
|
|
177
180
|
};
|
|
178
181
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
* Upstream Cloudflare API failures surfaced from an action. The message
|
|
183
|
+
* carries the upstream response body (Cloudflare's own error text — trusted
|
|
184
|
+
* infra, not user input), so it is echoed rather than redacted. `status`
|
|
185
|
+
* here is a fallback; each throw passes the actual upstream HTTP status.
|
|
186
|
+
*/
|
|
184
187
|
readonly ANALYTICS_SQL_ERROR: {
|
|
185
188
|
readonly status: 502;
|
|
186
189
|
readonly title: "Analytics Engine SQL API error";
|
|
@@ -197,21 +200,21 @@ declare const ERROR_CATALOG: {
|
|
|
197
200
|
/** A well-known Lunora error code (a key of {@link ERROR_CATALOG}). */
|
|
198
201
|
type LunoraErrorCode = keyof typeof ERROR_CATALOG;
|
|
199
202
|
/**
|
|
200
|
-
* True when `code` is an internal/redacted code — an internal failure or
|
|
201
|
-
* unhandled invariant whose `message` must NOT cross the wire (it may carry SQL
|
|
202
|
-
* fragments, file paths, or internal identifiers). Derived from the catalog's
|
|
203
|
-
* `internal` flag so the redaction posture stays in one place (the table).
|
|
204
|
-
* Throwing a `LunoraError` with any non-internal code is the author's vouch that
|
|
205
|
-
* its message is client-safe; an unknown/unregistered code is treated as safe.
|
|
206
|
-
*/
|
|
203
|
+
* True when `code` is an internal/redacted code — an internal failure or
|
|
204
|
+
* unhandled invariant whose `message` must NOT cross the wire (it may carry SQL
|
|
205
|
+
* fragments, file paths, or internal identifiers). Derived from the catalog's
|
|
206
|
+
* `internal` flag so the redaction posture stays in one place (the table).
|
|
207
|
+
* Throwing a `LunoraError` with any non-internal code is the author's vouch that
|
|
208
|
+
* its message is client-safe; an unknown/unregistered code is treated as safe.
|
|
209
|
+
*/
|
|
207
210
|
declare const isInternalCode: (code: string) => boolean;
|
|
208
211
|
/**
|
|
209
|
-
* A message-matched solution for errors that reach a consumer without a `code`
|
|
210
|
-
* — chiefly `@lunora/codegen` build errors, which are thrown as plain messages
|
|
211
|
-
* into generated code (and flattened to `{ message }` by the Vite overlay), so
|
|
212
|
-
* the message text is the only stable join key. Ordered most- to least-specific;
|
|
213
|
-
* the first matching rule wins.
|
|
214
|
-
*/
|
|
212
|
+
* A message-matched solution for errors that reach a consumer without a `code`
|
|
213
|
+
* — chiefly `@lunora/codegen` build errors, which are thrown as plain messages
|
|
214
|
+
* into generated code (and flattened to `{ message }` by the Vite overlay), so
|
|
215
|
+
* the message text is the only stable join key. Ordered most- to least-specific;
|
|
216
|
+
* the first matching rule wins.
|
|
217
|
+
*/
|
|
215
218
|
interface Solution {
|
|
216
219
|
/** Markdown body shown under the header. */
|
|
217
220
|
body: string;
|
|
@@ -226,27 +229,27 @@ interface SolutionRule extends Solution {
|
|
|
226
229
|
test: (message: string) => boolean;
|
|
227
230
|
}
|
|
228
231
|
/**
|
|
229
|
-
* Message-matched solutions (migrated verbatim from the former
|
|
230
|
-
* `@lunora/codegen` solutions table). Re-exported by `@lunora/codegen` as
|
|
231
|
-
* `LUNORA_SOLUTION_RULES` for backward compatibility.
|
|
232
|
-
*/
|
|
232
|
+
* Message-matched solutions (migrated verbatim from the former
|
|
233
|
+
* `@lunora/codegen` solutions table). Re-exported by `@lunora/codegen` as
|
|
234
|
+
* `LUNORA_SOLUTION_RULES` for backward compatibility.
|
|
235
|
+
*/
|
|
233
236
|
declare const MESSAGE_SOLUTIONS: ReadonlyArray<SolutionRule>;
|
|
234
237
|
/**
|
|
235
|
-
* Flatten a Markdown hint to plain text for a terminal / non-Markdown surface:
|
|
236
|
-
* drop code-fence markers and strip inline `**bold**` / `` `code` `` emphasis.
|
|
237
|
-
* Shared by the CLI renderer and the Studio `ErrorAlert` so the two can't drift.
|
|
238
|
-
*/
|
|
238
|
+
* Flatten a Markdown hint to plain text for a terminal / non-Markdown surface:
|
|
239
|
+
* drop code-fence markers and strip inline `**bold**` / `` `code` `` emphasis.
|
|
240
|
+
* Shared by the CLI renderer and the Studio `ErrorAlert` so the two can't drift.
|
|
241
|
+
*/
|
|
239
242
|
declare const flattenHint: (hint: ErrorHint) => string;
|
|
240
243
|
/**
|
|
241
|
-
* Find the first message-matched {@link Solution} for `message`, or `undefined`
|
|
242
|
-
* if none recognize it. Re-exported by `@lunora/codegen` as `findLunoraSolution`.
|
|
243
|
-
*/
|
|
244
|
+
* Find the first message-matched {@link Solution} for `message`, or `undefined`
|
|
245
|
+
* if none recognize it. Re-exported by `@lunora/codegen` as `findLunoraSolution`.
|
|
246
|
+
*/
|
|
244
247
|
declare const findSolutionByMessage: (message: string) => Solution | undefined;
|
|
245
248
|
/**
|
|
246
|
-
* Resolve an actionable hint for an error: prefer a hint carried on the error
|
|
247
|
-
* (or its `code`'s catalog entry), then fall back to a message match. Returns
|
|
248
|
-
* `undefined` when nothing recognizes it.
|
|
249
|
-
*/
|
|
249
|
+
* Resolve an actionable hint for an error: prefer a hint carried on the error
|
|
250
|
+
* (or its `code`'s catalog entry), then fall back to a message match. Returns
|
|
251
|
+
* `undefined` when nothing recognizes it.
|
|
252
|
+
*/
|
|
250
253
|
declare const resolveHint: (input: {
|
|
251
254
|
code?: string;
|
|
252
255
|
hint?: ErrorHint;
|
|
@@ -278,16 +281,16 @@ interface LunoraErrorOptions {
|
|
|
278
281
|
title?: string;
|
|
279
282
|
}
|
|
280
283
|
/**
|
|
281
|
-
* A code string: a well-known {@link LunoraErrorCode} (with autocomplete) or any
|
|
282
|
-
* package-specific code not yet in the catalog.
|
|
283
|
-
*/
|
|
284
|
+
* A code string: a well-known {@link LunoraErrorCode} (with autocomplete) or any
|
|
285
|
+
* package-specific code not yet in the catalog.
|
|
286
|
+
*/
|
|
284
287
|
type LunoraErrorCodeInput = LunoraErrorCode | (string & {});
|
|
285
288
|
declare class LunoraError extends Error {
|
|
286
289
|
/**
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
* Discriminator recognised by `@visulima/error`'s `renderError`/`isVisulimaError`
|
|
291
|
+
* (`error.type === "VisulimaError"`), so a `LunoraError` renders like a native
|
|
292
|
+
* `VisulimaError` — hint and all.
|
|
293
|
+
*/
|
|
291
294
|
readonly type = "VisulimaError";
|
|
292
295
|
/** Actionable fix (Markdown), rendered by the CLI/overlay/Studio. */
|
|
293
296
|
readonly hint: ErrorHint | undefined;
|
|
@@ -316,11 +319,11 @@ interface LunoraErrorLike extends Error {
|
|
|
316
319
|
type: "VisulimaError";
|
|
317
320
|
}
|
|
318
321
|
/**
|
|
319
|
-
* True when `error` carries the Lunora transport shape (string `code` + numeric
|
|
320
|
-
* `status` + the `VisulimaError` brand). The `type` brand is what distinguishes
|
|
321
|
-
* a real `LunoraError` (or its wire-decoded twin) from a foreign error that
|
|
322
|
-
* happens to carry `code`/`status` — see plan 119 for the full rationale.
|
|
323
|
-
*/
|
|
322
|
+
* True when `error` carries the Lunora transport shape (string `code` + numeric
|
|
323
|
+
* `status` + the `VisulimaError` brand). The `type` brand is what distinguishes
|
|
324
|
+
* a real `LunoraError` (or its wire-decoded twin) from a foreign error that
|
|
325
|
+
* happens to carry `code`/`status` — see plan 119 for the full rationale.
|
|
326
|
+
*/
|
|
324
327
|
declare const isLunoraError: (error: unknown) => error is LunoraErrorLike;
|
|
325
328
|
/** Throw an `INTERNAL` {@link LunoraError} when `condition` is falsy. */
|
|
326
329
|
declare const invariant: (condition: unknown, message: string) => asserts condition;
|
|
@@ -336,9 +339,9 @@ interface ErrorBody {
|
|
|
336
339
|
}
|
|
337
340
|
interface ToErrorBodyOptions {
|
|
338
341
|
/**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
* Wire-encode a `LunoraError`'s structured `data` for the client (so a
|
|
343
|
+
* `bigint`/`bytes` inside it survives). Omit to drop `data` from the body.
|
|
344
|
+
*/
|
|
342
345
|
encodeData?: (data: unknown) => unknown;
|
|
343
346
|
/** Code for an unrecognized (non-`LunoraError`) throw. Default `"INTERNAL"`. */
|
|
344
347
|
fallbackCode?: string;
|
|
@@ -353,12 +356,12 @@ interface ToErrorBodyResult {
|
|
|
353
356
|
status: number;
|
|
354
357
|
}
|
|
355
358
|
/**
|
|
356
|
-
* Turn a thrown value into an {@link ErrorBody} + status, applying the redaction
|
|
357
|
-
* invariant. A `LunoraError` with a non-internal code is echoed with its
|
|
358
|
-
* `message`, resolved `hint`, `docsUrl`, and (when `encodeData` is given) its
|
|
359
|
-
* `data`. An internal-coded `LunoraError` keeps its `code`/`status` but its
|
|
360
|
-
* message is replaced with `redactedMessage`. Anything else becomes a generic
|
|
361
|
-
* `fallbackCode`/500. When `redacted` is `true`, log the raw error server-side.
|
|
362
|
-
*/
|
|
359
|
+
* Turn a thrown value into an {@link ErrorBody} + status, applying the redaction
|
|
360
|
+
* invariant. A `LunoraError` with a non-internal code is echoed with its
|
|
361
|
+
* `message`, resolved `hint`, `docsUrl`, and (when `encodeData` is given) its
|
|
362
|
+
* `data`. An internal-coded `LunoraError` keeps its `code`/`status` but its
|
|
363
|
+
* message is replaced with `redactedMessage`. Anything else becomes a generic
|
|
364
|
+
* `fallbackCode`/500. When `redacted` is `true`, log the raw error server-side.
|
|
365
|
+
*/
|
|
363
366
|
declare const toErrorBody: (error: unknown, options?: ToErrorBodyOptions) => ToErrorBodyResult;
|
|
364
367
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { LunoraError } from './packem_shared/LunoraError-
|
|
2
|
-
export { ERROR_CATALOG, MESSAGE_SOLUTIONS, findSolutionByMessage, flattenHint, isInternalCode, resolveHint } from './packem_shared/ERROR_CATALOG-
|
|
1
|
+
export { LunoraError } from './packem_shared/LunoraError-DQkqKSaw.mjs';
|
|
2
|
+
export { ERROR_CATALOG, MESSAGE_SOLUTIONS, findSolutionByMessage, flattenHint, isInternalCode, resolveHint } from './packem_shared/ERROR_CATALOG-DaTEqgq6.mjs';
|
|
3
3
|
export { isLunoraError } from './packem_shared/isLunoraError-CSQtYMrF.mjs';
|
|
4
|
-
export { invariant, unreachable } from './packem_shared/invariant-
|
|
5
|
-
export { toErrorBody } from './packem_shared/toErrorBody-
|
|
4
|
+
export { invariant, unreachable } from './packem_shared/invariant-DFMi4YKZ.mjs';
|
|
5
|
+
export { toErrorBody } from './packem_shared/toErrorBody-BbkgBfL5.mjs';
|
|
@@ -197,7 +197,7 @@ const MESSAGE_SOLUTIONS = [
|
|
|
197
197
|
test: (message) => message.includes("optimistic concurrency conflict")
|
|
198
198
|
}
|
|
199
199
|
];
|
|
200
|
-
const flattenHint = (hint) => (
|
|
200
|
+
const flattenHint = (hint) => (typeof hint === "string" ? hint : hint.join("\n")).split("\n").filter((line) => !line.startsWith("```")).join("\n").replaceAll(/\*\*(.+?)\*\*/gu, "$1").replaceAll(/`([^`]+)`/gu, "$1");
|
|
201
201
|
const findSolutionByMessage = (message) => {
|
|
202
202
|
for (const rule of MESSAGE_SOLUTIONS) {
|
|
203
203
|
if (rule.test(message)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/errors",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"description": "Unified error layer for Lunora: one LunoraError base + a central catalog of codes, statuses, and actionable hints, rendered across CLI, overlay, Studio, and the client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|