Added error sub package

This commit is contained in:
2026-04-04 08:11:42 +02:00
parent 38d9df0367
commit 50282fe023
4 changed files with 59 additions and 38 deletions

45
source/errors.mjs Normal file
View File

@@ -0,0 +1,45 @@
import { inspect } from 'node:util';
// § GROUP: Resolving errors
export class Item_Unresolvable extends Error {
constructor(data) {
const { resolver, item } = data;
const type = item === null ? 'null' : typeof item;
super(`Cannot resolve item ${inspect(item)} of type "${type}" using resolver ${resolver}`);
this.data = data;
}
}
// § GROUP: Storage errors
export class Not_Storable_Error extends Error {
constructor(data) {
const { storage, value, property, id } = data;
const type = value === null ? 'null' : typeof value;
const location = property ? `property "${property}" of record #${id}` : `record #${id}`;
super(`Cannot store value of type "${type}" in ${location}: ${inspect(value)}`);
this.data = data;
}
}
export class Not_Mutable_Error extends Error {
constructor(data) {
const { storage, value, property, id } = data;
const type = value === null ? 'null' : typeof value;
const location = property ? `property "${property}" of record #${id}` : `record #${id}`;
super(`Cannot set ${location}: record is immutable (tried to store value of type "${type}": ${inspect(value)})`);
this.data = data;
}
}
export class No_Such_Object_Index_Error extends Error {
constructor(data) {
const { storage, property, id } = data;
const location = property ? `property "${property}" of record #${id}` : `record #${id}`;
super(`Cannot get ${location}: no such record index`);
this.data = data;
}
}