Class: SchemaError
Defined in: src/Mnemonic/schema.ts:47
Error thrown for schema registry, versioning, and migration failures.
Each instance carries a machine-readable code that categorises
the failure. When a defaultValue factory is provided to
useMnemonicKey, the SchemaError is passed as the error argument
so the factory can inspect the failure reason.
Error codes:
| Code | Meaning |
|---|---|
INVALID_ENVELOPE | The raw stored value is not a valid MnemonicEnvelope. |
SCHEMA_NOT_FOUND | No schema registered for the stored key + version. |
WRITE_SCHEMA_REQUIRED | Strict mode requires a schema to write, but none was found. |
MIGRATION_PATH_NOT_FOUND | No contiguous migration path between the stored and latest version. |
MIGRATION_FAILED | A migration step threw during execution. |
MIGRATION_GRAPH_INVALID | The schema registry helper received an ambiguous or cyclic migration graph. |
RECONCILE_FAILED | A read-time reconciliation hook threw or returned an unpersistable value. |
SCHEMA_REGISTRATION_CONFLICT | registerSchema was called with a conflicting definition. |
TYPE_MISMATCH | The decoded value failed JSON Schema validation. |
MODE_CONFIGURATION_INVALID | The schema mode requires a capability the registry doesn't provide. |
Example
defaultValue: (error) => {
if (error instanceof SchemaError) {
console.warn(`Schema issue [${error.code}]:`, error.message);
}
return { name: "Guest" };
}
See
- SchemaMode - How the provider uses schemas
- SchemaRegistry - Where schemas and migrations are registered
Extends
Error
Constructors
Constructor
new SchemaError(
code,message,cause?):SchemaError
Defined in: src/Mnemonic/schema.ts:75
Creates a new SchemaError.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | "INVALID_ENVELOPE" | "SCHEMA_NOT_FOUND" | "WRITE_SCHEMA_REQUIRED" | "MIGRATION_PATH_NOT_FOUND" | "MIGRATION_FAILED" | "MIGRATION_GRAPH_INVALID" | "RECONCILE_FAILED" | "SCHEMA_REGISTRATION_CONFLICT" | "TYPE_MISMATCH" | "MODE_CONFIGURATION_INVALID" | Machine-readable failure category |
message | string | Human-readable error description |
cause? | unknown | Optional underlying error |
Returns
SchemaError
Overrides
Error.constructor
Properties
cause?
readonlyoptionalcause:unknown
Defined in: src/Mnemonic/schema.ts:66
The underlying error that caused this failure, if any.
code
readonlycode:"INVALID_ENVELOPE"|"SCHEMA_NOT_FOUND"|"WRITE_SCHEMA_REQUIRED"|"MIGRATION_PATH_NOT_FOUND"|"MIGRATION_FAILED"|"MIGRATION_GRAPH_INVALID"|"RECONCILE_FAILED"|"SCHEMA_REGISTRATION_CONFLICT"|"TYPE_MISMATCH"|"MODE_CONFIGURATION_INVALID"
Defined in: src/Mnemonic/schema.ts:51
Machine-readable code identifying the category of schema failure.
message
message:
string
Defined in: website/node_modules/typescript/lib/lib.es5.d.ts:1077
Inherited from
Error.message
name
name:
string
Defined in: website/node_modules/typescript/lib/lib.es5.d.ts:1076
Inherited from
Error.name
stack?
optionalstack:string
Defined in: website/node_modules/typescript/lib/lib.es5.d.ts:1078