Skip to content

refactor: use the SDK's error predicates instead of local copies - #70

Open
lmjabreu wants to merge 2 commits into
mainfrom
lmjabreu/use-sdk-error-helpers
Open

lmjabreu wants to merge 2 commits into
mainfrom
lmjabreu/use-sdk-error-helpers

Conversation

@lmjabreu

@lmjabreu lmjabreu commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Overview

@doist/comms-sdk 3.3.0 now exports isNotFound, isConflict, isMalformedId, getCommsErrorCode and getCommsErrorString, which #66 had to write locally. This deletes our copies and imports the SDK's.

Reference

Follows @scottlovegrove's review on #66 and Doist/comms-sdk-typescript#83. The 401 and 403 helpers stay here: isForbidden means "a 403 that is not a scope failure", which is our policy rather than a property of the response.

The SDK helpers check instanceof CommsRequestError, as status.ts already does, where ours accepted any object with an httpStatusCode. Nothing in the CLI passes one that isn't an instance.

The bump from 3.0.0 also picks up 3.1.0 and 3.2.0 (thread image reads, retry back-off, a clearer message when a request fails at the network layer), and moves undici to 7.30.0 with it.

Changelog

Internal only. Error messages for 404, malformed ids and other 409s are unchanged.

Test plan

  1. tdc thread view id:nope
    • Error: INVALID_REF with the server's message, no stack trace
  2. tdc thread view id:<a well-formed id that does not exist>
    • Error: NOT_FOUND
  3. tdc thread view id:<a thread you can see>
    • Shows the thread

🤖 Generated with Claude Code

@doist/comms-sdk 3.3.0 exports isNotFound, isConflict, isMalformedId,
getCommsErrorCode and getCommsErrorString, which #66 had to write locally.
Delete ours, bump the SDK pin, and import them in api.ts.

The SDK's versions narrow with instanceof CommsRequestError, as status.ts
already does, where ours duck-typed any object with an httpStatusCode. The
401 and 403 helpers stay here: isForbidden is "a 403 that is not a scope
failure", which is CLI policy rather than a property of the response.

api.test.ts replaced the whole SDK module with a mock that included a fake
CommsRequestError, which an instanceof check can never match. It now fakes
only CommsApi and keeps the real error class and helpers, so the status
mapping is tested against the code it depends on.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lmjabreu
lmjabreu requested review from scottlovegrove and removed request for scottlovegrove October 1, 2026 15:32
@lmjabreu

lmjabreu commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@doistbot /review

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR swaps the locally duplicated SDK error predicates (isNotFound, isConflict, isMalformedId, getCommsErrorCode, getCommsErrorString) for the new exports in @doist/comms-sdk 3.3.0, intentionally keeping the 401/403 helpers local since isForbidden encodes CLI policy rather than response shape.

Few things worth tightening:

  • The partial SDK mock in src/commands/migrate/migrate.test.ts only provides fetchNewCommsUrls, so it no longer covers the getCommsErrorString import that errors.ts pulls in transitively — update it to spread importActual (as api.test.ts now does) or supply the missing export.

Share Feedback • Review Logs

Comment thread src/lib/errors.ts
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lmjabreu
lmjabreu marked this pull request as ready for review October 1, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants