Introduce HarnessError in dsh-llm (the leaf package): a stable machine-routable
code distinct from the message, cause chaining, name from the subclass, plus
isHarnessError. LlmError, ToolArgsError, and InvariantError now extend it.
Tool failures carry the structure end-to-end: ToolExecutionResult gains
error: { name, code } (populated from a thrown HarnessError), and the loop
forwards it onto the tool/result session event (which gained the same optional
field) for retry/sandbox plugins and replay. The loop's toError wraps non-Error
throws in a HarnessError(code: UNKNOWN, cause) instead of a bare Error.
Landed last and in isolation so it's a pure upgrade over the plain Error+code
the earlier PRs used — independently revertible. Graduates RFC 005 pt 2 ->
ADR 0015; RFC 005 now fully implemented.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/**
|
|
* The harness error taxonomy: one base class so failures carry a stable,
|
|
* machine-routable `code` and chain their `cause`, instead of flattening to a
|
|
* bare message string. Per-package errors extend {@link HarnessError}; the
|
|
* tool layer surfaces `{ name, code }` on results and the session `tool/result`
|
|
* event so retry/sandbox plugins and replay can distinguish failure classes.
|
|
*
|
|
* Lives in dsh-llm (the leaf package every other imports) so a single base is
|
|
* shared without a new dependency edge. See ADR 0015.
|
|
*
|
|
* @module @deepseek-ai/dsh-llm/error
|
|
*/
|
|
|
|
/**
|
|
* Base class for all harness errors. Carries a `code` (stable, programmatic —
|
|
* e.g. `NO_ADAPTER`, `INVALID_ARGS`, `INVARIANT`) distinct from the
|
|
* human-readable `message`, and supports `cause` chaining via the standard
|
|
* `ErrorOptions`. `name` defaults to the subclass constructor name.
|
|
*/
|
|
export class HarnessError extends Error {
|
|
readonly code: string
|
|
|
|
constructor(message: string, code: string, options?: ErrorOptions) {
|
|
super(message, options)
|
|
this.code = code
|
|
this.name = new.target.name
|
|
}
|
|
}
|
|
|
|
/** Narrow an arbitrary thrown value to a HarnessError (for `instanceof` at seams). */
|
|
export function isHarnessError(value: unknown): value is HarnessError {
|
|
return value instanceof HarnessError
|
|
}
|