- 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
2.4 KiB
2.4 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | |
|---|---|---|---|---|---|---|---|---|
| error/error-hierarchy | Implement typed error class hierarchy | completed |
|
narrow | trivial | phase | implementation |
Description
Implement the custom error classes in src/error/index.ts per errors-validation.md. All errors extend TaskgraphError which extends Error. Each subclass adds typed fields for programmatic error recovery.
Acceptance Criteria
src/error/index.tsexports:TaskgraphError extends Error— base classTaskNotFoundError extends TaskgraphErrorwithtaskId: stringfieldCircularDependencyError extends TaskgraphErrorwithcycles: string[][]fieldInvalidInputError extends TaskgraphErrorwithfield: stringandmessage: stringfieldsDuplicateNodeError extends TaskgraphErrorwithtaskId: stringfieldDuplicateEdgeError extends TaskgraphErrorwithprerequisite: stringanddependent: stringfields
- Each error class sets
this.nameto the class name - Each error class properly extends the prototype chain (
Object.setPrototypeOf(this, new.target.prototype)) InvalidInputErrorsupports construction from TypeBoxValue.Errors()output (receives structured field/path/value info)CircularDependencyErrorreceivesstring[][]where each inner array is an ordered cycle path- Unit tests verifying: correct
instanceofchain, field access,.nameproperty, error messages
References
- docs/architecture/errors-validation.md — error types, when each is thrown
- docs/architecture/api-surface.md — error documentation on specific methods
Notes
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
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