Initial Commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { defineCodes, SuaveplanError } from "@suaveplan/error";
|
||||
|
||||
/**
|
||||
* Stable error-code registry for `@suaveplan/test-vite`.
|
||||
*
|
||||
* Codes follow `TEST_VITE.<REASON>` and are produced by
|
||||
* `@suaveplan/error`'s `defineCodes` so the namespace survives module
|
||||
* boundaries and runtime serialisation. Consumers SHOULD discriminate on
|
||||
* `error.code` rather than `instanceof` so the discriminator works across
|
||||
* worker, RPC, and serialised-error boundaries.
|
||||
*/
|
||||
export const TEST_VITE_CODES = defineCodes("TEST_VITE", [
|
||||
"INVALID_OPTIONS",
|
||||
"MISSING_ENTRY",
|
||||
"TREE_SHAKE_VIOLATION",
|
||||
"SIZE_BUDGET_EXCEEDED",
|
||||
"SNAPSHOT_MISSING",
|
||||
"PORT_EXHAUSTED",
|
||||
"PORT_NOT_HELD",
|
||||
"HMR_TIMEOUT",
|
||||
] as const);
|
||||
|
||||
export type TestViteCode =
|
||||
(typeof TEST_VITE_CODES)[keyof typeof TEST_VITE_CODES];
|
||||
|
||||
/**
|
||||
* Typed error class for every `@suaveplan/test-vite` failure path.
|
||||
*
|
||||
* Carries the registered code, a human-readable message, and an optional
|
||||
* structured `details` payload through the `SuaveplanError` `context`
|
||||
* field so callers can drive diagnostics without re-parsing the message.
|
||||
*/
|
||||
export class TestViteError extends SuaveplanError<TestViteCode> {
|
||||
public readonly details: Record<string, unknown>;
|
||||
|
||||
public constructor(
|
||||
code: TestViteCode,
|
||||
message: string,
|
||||
options?: {
|
||||
cause?: unknown;
|
||||
details?: Record<string, unknown>;
|
||||
}
|
||||
) {
|
||||
super(code, message, {
|
||||
...(options?.cause === undefined ? {} : { cause: options.cause }),
|
||||
context: options?.details ?? {},
|
||||
});
|
||||
this.name = "TestViteError";
|
||||
this.details = options?.details ?? {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user