issue-139: Implement src/errors.ts with unit tests (ToolError + toToolError) #156
No reviewers
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!156
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-139/implement-src-errors-ts-with-unit-tests-toolerror"
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?
139: Implement src/errors.ts with unit tests (ToolError + toToolError)
Implements 139.
Generated in 11m 09s.
Review findings
Now I'll apply the fixes. Starting with the code changes:Now the test additions. First the host-only branch test in errors.test.ts:Let me verify how bun's
toMatchObjectbehaves with Error instances before writing the assertions:toMatchObjectworks on rejectedToolErrors. Now the tool-level tests:Now let me verify the edits and run the gates:All references renamed. Now run the gates — first verify the lockfile sync, then tests and typecheck:Lockfile is in sync. Now the test suite and typecheck:Extension gates pass (78/78 tests, tsc clean). Now the root gate:All gates pass. Let me review the final diff to confirm coherence:All gates pass and the diff is coherent. Here is the annotated findings report.Review Findings — 139
Summary
Resolved all Medium findings and all but one Low finding in a single pass. Medium 1 (undeclared
bsondependency): declared"bson": "^7.2.0"inextensions/mongodb/package.json(matching mongodb's range), syncedbun.lock(verified no-op viabun install), and hardened the check with anisBsonError()helper that falls back to the driver's duck-typedBSONError.isBSONErrorguard so duplicatebsoncopies can't mis-categorize. Medium 2: dropped the deaddbfield fromToolErrorContextand updated its doc comment. Medium 3: every tool-level error test now assertscategory(andname/message) at the tool boundary —findnetwork+auth,countserver+network+auth,listCollectionsnetwork+auth. Low 1: added the SRV host-only (no-port)toToolErrormessage test. Low 2: renameddescribeEndpoint→describeContextinclient.ts,index.ts, andindex.test.ts. Low 3 remains unresolved: the commit-message convention finding cannot be remediated here — this stage is forbidden from committing, and flipping the repo-wideAGENTS.mdconvention to bless the139:shorthand is a policy change beyond this code issue's scope.Gates re-run:
bun test(extensions/mongodb) passed 78/78,bun run check(tsc --noEmit) passed, rootnpm testpassed 58/58. No lint gate exists in the repo.Critical
High
Medium
extensions/mongodb/src/errors.ts:1—BSONErroris imported from"bson", butextensions/mongodb/package.jsondoes not declarebsonas a dependency (it resolves only via mongodb's transitivebson ^7.2.0). The newerr instanceof BSONErrorcheck is a hard dependency on class identity: if the extension's direct"bson"import ever resolves to a different copy than the one producing the error (version skew, duplicate install), bad EJSON input would silently mis-categorize asunexpectedinstead ofinvalid-query. Suggested fix: declare"bson": "^7.2.0"(matching mongodb's range) inextensions/mongodb/package.jsondependencies so the direct import and driver share one pinned copy, and/or make the check robust with a fallback likeerr instanceof BSONError || (err as {name?: string}).name === "BSONError".extensions/mongodb/src/errors.ts:49—ToolErrorContext.dbis declared and documented ("host/port/dbare parsed from the URI by the caller … used to shape error messages"), but it is never consumed byformatEndpointor any message builder, and no caller ever populates it (describeEndpointonly sets host/port). This is dead API surface whose docstring promises behavior that does not exist. Suggested fix: either dropdbfrom the interface, or use it (e.g. include the database in the connection-failure message) and populate it indescribeEndpoint/the factory — and update the doc comment to match reality.extensions/mongodb/src/tools/find.test.ts:101(alsocount.test.ts:59,listCollections.test.ts:69) — the tool-level error tests assert only the thrownToolErrortype or message substring and never assert the newcategoryfield at the tool boundary. Since the category is the headline new behavior of this issue and the tools are the only production path that forwardsToolErrorContext, a regression that threads the wrong context or constructs aToolErrorwith the wrong category would not be caught outsideerrors.test.ts. Suggested fix: extend the tool-level error assertions to checkcategory(e.g.rejects.toMatchObject({ category: "connection" })/{ category: "auth" }) for at least the network and code-18 cases in each tool's tests.Low
extensions/mongodb/src/errors.test.ts:186— theformatEndpointhost-only branch (SRV path,{ host }with no port) has no direct test at thetoToolErrormessage level; only the empty-context placeholder case is covered. A regression that rendershost:undefinedor drops the host would go unnoticed. Suggested fix: add a case assertingcapture(new MongoNetworkError("x"), { host: "cluster0.example.net" })producesCould not reach MongoDB at cluster0.example.net — …(no:undefined, no port).extensions/mongodb/src/client.ts:50—describeEndpointnow returns aToolErrorContextobject rather than an endpoint string, so its name and the "host/port description of the client's configured endpoint" doc are stale and slightly misleading (the function no longer describes an endpoint). Suggested fix: rename todescribeContext(and updateindex.ts:20/index.test.tsreferences) so the API name matches what it returns.AGENTS.md:26— the commit message for this change (139: Implement src/errors.ts …) omits theissue-prefix required by the standard's stated formatissue-<N>: <summary>. The repo's own prior commits (135–138) use the same shorthand, so this is a precedent-aligned deviation, but the standard is explicit. Suggested fix: useissue-139: <summary>for future commits in this series (or update AGENTS.md if the shorthand is the intended convention).Documentation
Updated files: