feat(error/error-hierarchy): implement typed error class hierarchy

- Add typed fields to all error subclasses (taskId, cycles, field, message, prerequisite, dependent)
- Set Object.setPrototypeOf(this, new.target.prototype) in all constructors
- Add InvalidInputError.fromTypeBoxError() static factory for TypeBox Value.Errors() output
- CircularDependencyError accepts string[][] for cycle paths
- 31 unit tests covering instanceof chain, field access, .name property, and error messages
This commit is contained in:
2026-04-27 10:00:40 +00:00
parent bd8a7b06d0
commit ce68271f4f
3 changed files with 316 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
---
id: error/error-hierarchy
name: Implement typed error class hierarchy
status: pending
status: completed
depends_on:
- setup/project-init
scope: narrow
@@ -16,18 +16,18 @@ Implement the custom error classes in `src/error/index.ts` per [errors-validatio
## Acceptance Criteria
- [ ] `src/error/index.ts` exports:
- [x] `src/error/index.ts` exports:
- `TaskgraphError extends Error` — base class
- `TaskNotFoundError extends TaskgraphError` with `taskId: string` field
- `CircularDependencyError extends TaskgraphError` with `cycles: string[][]` field
- `InvalidInputError extends TaskgraphError` with `field: string` and `message: string` fields
- `DuplicateNodeError extends TaskgraphError` with `taskId: string` field
- `DuplicateEdgeError extends TaskgraphError` with `prerequisite: string` and `dependent: string` fields
- [ ] Each error class sets `this.name` to the class name
- [ ] Each error class properly extends the prototype chain (`Object.setPrototypeOf(this, new.target.prototype)`)
- [ ] `InvalidInputError` supports construction from TypeBox `Value.Errors()` output (receives structured field/path/value info)
- [ ] `CircularDependencyError` receives `string[][]` where each inner array is an ordered cycle path
- [ ] Unit tests verifying: correct `instanceof` chain, field access, `.name` property, error messages
- [x] Each error class sets `this.name` to the class name
- [x] Each error class properly extends the prototype chain (`Object.setPrototypeOf(this, new.target.prototype)`)
- [x] `InvalidInputError` supports construction from TypeBox `Value.Errors()` output (receives structured field/path/value info)
- [x] `CircularDependencyError` receives `string[][]` where each inner array is an ordered cycle path
- [x] Unit tests verifying: correct `instanceof` chain, field access, `.name` property, error messages
## References
@@ -36,8 +36,11 @@ Implement the custom error classes in `src/error/index.ts` per [errors-validatio
## Notes
> To be filled by implementation agent
InvalidInputError overrides `message` property to provide the validation-specific message while still calling `super()` with a combined message for the Error base. A static `fromTypeBoxError()` factory method converts TypeBox `Value.Errors()` output (with `/path` format) to the proper `field` string by stripping the leading slash.
## Summary
> To be filled on completion
Implemented the full typed error class hierarchy in `src/error/index.ts`.
- Modified: `src/error/index.ts` — rewrote skeleton to add typed fields, prototype chain setup, and TypeBox factory method
- Created: `test/error.test.ts` — 31 unit tests covering instanceof chain, field access, .name property, error messages, and TypeBox integration
- Tests: 36 passing (31 error-specific + 5 existing placeholders), all lint clean