38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import type { SuaveplanErrorOptions } from "@suaveplan/error";
|
|
import { defineCodes, SuaveplanError } from "@suaveplan/error";
|
|
|
|
/**
|
|
* Frozen registry of every code emitted by `create-suaveplan-plugin`.
|
|
*
|
|
* Each value is namespaced as `SCAFFOLD.<REASON>` and the registry itself
|
|
* is frozen at module-load time so consumers can rely on `instanceof` plus
|
|
* literal-typed `code` for exhaustive switches.
|
|
*/
|
|
export const SCAFFOLD_CODES = defineCodes("SCAFFOLD", [
|
|
"INVALID_NAME",
|
|
"DIRECTORY_EXISTS",
|
|
"WRITE_FAILED",
|
|
"UNKNOWN_ENGINE",
|
|
] as const);
|
|
|
|
export type ScaffoldErrorCode =
|
|
(typeof SCAFFOLD_CODES)[keyof typeof SCAFFOLD_CODES];
|
|
|
|
/**
|
|
* Typed error for every `create-suaveplan-plugin` failure path.
|
|
*
|
|
* Extends `SuaveplanError` with a literal code drawn from
|
|
* `SCAFFOLD_CODES`, so consumers can `instanceof ScaffoldError` and then
|
|
* narrow on `.code` without losing exhaustiveness.
|
|
*/
|
|
export class ScaffoldError extends SuaveplanError<ScaffoldErrorCode> {
|
|
public constructor(
|
|
code: ScaffoldErrorCode,
|
|
messageKey: string,
|
|
options?: SuaveplanErrorOptions
|
|
) {
|
|
super(code, messageKey, options);
|
|
this.name = "ScaffoldError";
|
|
}
|
|
}
|