Add isAbortError to @solana/promises#1549
Conversation
🦋 Changeset detectedLatest commit: 6e1e66f The changes in this PR will be included in the next version bump. This PR includes changesets to release 46 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
BundleMonFiles updated (3)
Unchanged files (141)
Total files change +126B +0.02% Final result: ✅ View report in BundleMon website ➡️ |
|
Documentation Preview: https://kit-docs-e7syjl5cf-anza-tech.vercel.app |
trevor-cortex
left a comment
There was a problem hiding this comment.
Nice, tidy addition. Adds isAbortError(err) to @solana/promises as a narrow predicate — err instanceof Error && err.name === 'AbortError' — so callers don't have to instanceof-check each platform's error class. Pairs well with getAbortablePromise and standard fetch abort behavior.
What looks good
- Export is automatic via the existing
export * from './abortable'insrc/index.ts, no index change needed. minorchangeset is correct for a new public API.- JSDoc follows the repo's docblock skill (summary,
@example,@see {@link getAbortablePromise}). - README section mirrors the style of the adjacent
getAbortablePromiseentry. - Tests cover the happy path, a subclass, the real abort flow through
getAbortablePromise, and the main negative cases (regularError,TypeError, duck-typed object,undefined,null).expect.assertions(1)is correctly used only in the async test, per CLAUDE.md.
For subsequent reviewers
- The docblock specifically mentions
DOMExceptionas the real-world aborted-fetch rejection, but the tests simulate it withObject.assign(new Error(), { name: 'AbortError' })rather than a realnew DOMException('...', 'AbortError').DOMExceptionextendsErrorin all environments Kit targets (Node ≥17 current/lts, browsers, RN) so the predicate works, but a directDOMExceptiontest would tie the behavior more tightly to the documented use case. Non-blocking. - Worth sanity-checking that
@solana/promisesgenuinely isn't intended to be re-exported from the@solana/kitfacade — it currently isn't (neithergetAbortablePromisenor the newisAbortErrorwill be reachable from@solana/kit). That's pre-existing and out of scope for this PR, just flagging.
| it('returns `false` for a non-`Error` object whose `name` is `AbortError`', () => { | ||
| expect(isAbortError({ name: 'AbortError' })).toBe(false); | ||
| }); | ||
| it('returns `false` for `undefined`', () => { |
There was a problem hiding this comment.
Optional: since the docblock specifically calls out DOMException as the real-world aborted-fetch rejection shape, consider adding a case that uses the real thing:
it('returns `true` for a `DOMException` whose `name` is `AbortError`', () => {
expect(isAbortError(new DOMException('The operation was aborted.', 'AbortError'))).toBe(true);
});This exercises the instanceof Error branch against the actual platform class rather than a synthesized Error with a patched name, and guards against any future environment where DOMException stops extending Error. Non-blocking.
There was a problem hiding this comment.
Good idea - had to add this as a browser only test because of a limitation of Jest's node env.
f5f38cb to
15de2e4
Compare
lorisleiva
left a comment
There was a problem hiding this comment.
Thanks! I double-checked and it also works when passing nothing to AbortController.abort (See playground). nit: Maybe we could add a test case like this.
Adds `isAbortError(err)` to `@solana/promises`. The helper narrows `unknown` to `Error` and returns `true` when the error's `name` is `'AbortError'` — the convention used by `DOMException` and by `AbortController`-aware APIs like `fetch`. Callers catching rejections from `getAbortablePromise`, superseded operations, or other abort-aware flows can use this to distinguish intentional cancellation from real failures without having to `instanceof`-check every platform-specific error class. Ships with test coverage across Node and browser environments and a README entry demonstrating the try/catch pattern alongside `getAbortablePromise`.
15de2e4 to
6e1e66f
Compare
|
Nice, thanks! Added to the browser tests because it has the same quirk in Jest's Node environment. |
|
🔎💬 Inkeep AI search and chat service is syncing content for source 'Solana Kit Docs' |
|
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |

Summary of Changes
This PR adds a new function
isAbortErrorto@solana/promisesIt provides an easy way to filter for an abort error, in the same way we do with
isSolanaError. Pairs withgetAbortablePromise, but useful for anything throwing abort errors (like fetch) too.