/** * Typed errors for the v2 posting path so callers can react precisely. */ export { RecipeRefusalError } from './core/core.errors.js'; export type { TRecipeRefusalCode, IRecipeRefusalDetails } from './core/core.errors.js'; export class ImmutableEntryError extends Error { constructor(entryId: string) { super( `Journal entry ${entryId} is festgeschrieben (hashed) and immutable — corrections only via Storno entries`, ); this.name = 'ImmutableEntryError'; } } export class PeriodLockedError extends Error { constructor(skrType: string, period: string) { super(`Period ${period} (${skrType}) is festgeschrieben — no further postings allowed`); this.name = 'PeriodLockedError'; } } export class SequenceConflictError extends Error { constructor(skrType: string, fiscalYear: number) { super( `Hash-chain head moved concurrently for ${skrType}/${fiscalYear} — transaction aborted`, ); this.name = 'SequenceConflictError'; } } export class NotImplementedError extends Error { constructor(feature: string) { super(feature); this.name = 'NotImplementedError'; } } export class TransactionsUnsupportedError extends Error { constructor(detail: string) { super( `The database does not support transactions (a NoSQLDB engine, or a MongoDB replica set, is required) — filing-grade posting has no non-transactional fallback. ${detail}`, ); this.name = 'TransactionsUnsupportedError'; } } /** One (skrType, accountNumber, reference) key held by more than one OposMeta document. */ export interface IOposMetaDuplicate { skrType: string; accountNumber: string; reference: string; count: number; } /** * The storage migration found dunning metadata recorded more than once for one * open item, so the unique index over OposMeta cannot be created. Nothing is * deleted: resolve the duplicates by hand, then start skr again. */ export class OposMetaDuplicatesError extends Error { public readonly duplicates: IOposMetaDuplicate[]; constructor(duplicates: IOposMetaDuplicate[]) { const keys = duplicates .map((entry) => `${entry.skrType}/${entry.accountNumber}/${entry.reference} (${entry.count}×)`) .join(', '); super( `OposMeta holds more than one dunning record for ${duplicates.length} open item(s): ${keys}. ` + 'Merge each into one document by hand; skr deletes no financial metadata.', ); this.name = 'OposMetaDuplicatesError'; this.duplicates = duplicates; } } /** * A classic write that cannot map 1:1 onto the hashed journal: it would write * the frozen v1 shape (a standalone Transaction, an unposted or in-place * posted JournalEntry, a mutated original on reversal), which no balance, * report or export reads. The message names the API that books it instead. */ export class RetiredLedgerWriteError extends Error { constructor(method: string, reason: string, replacement: string) { super(`${method} no longer writes to the database: ${reason}. Use ${replacement} instead.`); this.name = 'RetiredLedgerWriteError'; } } /** * The ledger migration met stored data it cannot book on without guessing: a * legacy transaction already imported more than once or with other content, * a sequence counter ahead of the journal, or a chain that does not verify. * Nothing is changed or deleted: the issues name what to resolve by hand * before skr is started again. */ export class LedgerMigrationConflictError extends Error { public readonly issues: string[]; constructor(issues: string[]) { super( `The ledger migration stopped before booking on conflicting data: ${issues.join('; ')}. ` + 'Resolve it by hand from a backup; skr deletes no financial data.', ); this.name = 'LedgerMigrationConflictError'; this.issues = issues; } } /** * A migration step stopped because its lease passed to another process, or * could not be renewed before it ran out. Every step resumes where it * stopped: start skr again once the other process is done. */ export class MigrationLeaseLostError extends Error { constructor(stepId: string, detail: string) { super(`Migration ${stepId} stopped: its lease ${detail}. Start skr again once the other process is done.`); this.name = 'MigrationLeaseLostError'; } }