Implement extensions/vision/src/errors.ts (ToolError + categories) #253
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#253
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Create
extensions/vision/src/errors.ts, exporting theToolErrorclass and theToolErrorCategoryunion that every othervisionmodule throws to fail a tool call. This is the foundation the rest of the extension is written against, so it lands first.Background
The
visionextension turns a local image-understanding CLI into a pi tool. pi only reports a tool call as failed whenexecute()throws; returning a value never setsisError(pinned pi docs,docs/extensions.md, "Signaling errors"). The extension therefore funnels every failure through one typed error so callers and tests can distinguish categories while the LLM only ever sees an actionable message — never a raw stack trace.This mirrors the sibling
extensions/mongodb/src/errors.ts, which already establishes the pattern in this repo (aToolErrorclass carrying acategory, withname = "ToolError").Downstream modules (
config.ts,images.ts,client.ts,tool.ts) all importToolErrorandToolErrorCategoryfrom here, so this module must have no dependencies of its own on othervisionmodules.Documentation Required
A separate process downloads these into the listed folders before this issue is implemented. Check the folder for the actual reference material before starting.
docs/reference/pi-coding-agent/node_modules/@earendil-works/pi-coding-agent/docs/extensions.md, section "Signaling errors" — the throw-to-fail contract (returning a value never sets the error flag). The docs are shipped inside the installed package; the canonical location in this repo is that path.execute()error handling — how a thrown error is surfaced to the LLM/UI.docs/reference/typescript/Errorcorrectly (prototype,name,message), soinstanceof ToolErrorworks in tests.Implementation Details
Create
extensions/vision/src/errors.tswith exactly this public surface:Requirements:
constructorcallssuper(message), setsthis.name = "ToolError"andthis.category = category(readonly field).extensions/mongodb/src/errors.tsfor shape/naming; use the exact 10 categories above (this repo's other extensions use their own category sets — do not copy those).visionfiles so it can be imported anywhere with no cycle.node --testdirectly against.tsfiles (Node 24 strips types natively), so useimport typewhere appropriate.Test file
extensions/vision/src/errors.test.ts(write it first, TDD):new ToolError("msg", "image")isinstanceof Errorandinstanceof ToolError.name === "ToolError",messagepreserved verbatim,categorypreserved verbatim.ToolErrorcan be thrown and caught withcategoryintact.satisfies/ typed array is enough).Acceptance Criteria
extensions/vision/src/errors.tsexportsToolErrorandToolErrorCategorywith the exact 10 categories listed above.ToolErrorextendsError, setsname = "ToolError", and stores the category in areadonly categoryfield.visionmodules.string) and noanyescapes into the public surface.extensions/vision/src/errors.test.tsexists and assertsinstanceof,name,message,category, and throw/catch behaviour.node --test extensions/vision/src/errors.test.tspasses from the repo root.Test Plan
Expected: all tests pass, zero network access, no files written.
Quick manual confirmation that the types are usable from a later module:
Expected:
ToolError timeout true.pi-loop opened and merged a pull request for this issue: #267