Files
taskgraph_ts/tasks/implementation/error/error-hierarchy.md
glm-5.1 ce68271f4f 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
2026-04-27 10:00:40 +00:00

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
setup/project-init
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.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

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