Skip to content

keyv - fix: follow the EventEmitter error rule and remove throwOnErrors - #2155

Merged
jaredwray merged 2 commits into
mainfrom
claude/wizardly-lamport-lyi7hy
Sep 26, 2026
Merged

jaredwray merged 2 commits into
mainfrom
claude/wizardly-lamport-lyi7hy

Conversation

@jaredwray

@jaredwray jaredwray commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.
    • The throwOnErrors tests in test/keyv.test.ts are replaced with tests of the listener rule for all eleven operations, plus tests for iterator and for how failed reads count in stats. The two setRaw/setManyRaw tests now check the no-listener rejection. New Redis tests check that each failure is reported once.

What kind of change does this PR introduce? Bug fix, and removal of the throwOnErrors option. This supersedes #2154.

Problem

throwOnErrors never did what it promised. Keyv passed it to Hookified as throwOnEmitError, which Hookified only reads when an error event has no listeners. In that case Keyv already throws, through throwOnEmptyListeners. With a listener attached, the option did nothing.

It couldn't be fixed only in Keyv either. DynamoDB, Cloudflare KV, etcd, Memcache, and Redis (by default) catch their own failures, emit error, and return a fallback value. For those adapters, #2154's fix still returned undefined with the option on and a listener attached. Making the option work would have needed a throw mode in every adapter.

getMany, getRaw, getManyRaw, and iterator had the opposite problem. They didn't catch store errors, so they rejected even with a listener attached, and they emitted no error event.

Changes

  • One rule, the Node.js EventEmitter one. When an operation fails, Keyv emits error. With a listener attached, the call returns a fallback value. With none, it rejects. This is what main already does for most methods.
  • throwOnErrors removed: the option, getter, setter, and type are gone. Keyv no longer passes a throw setting to Hookified, so a future change to Hookified's throwOnEmitError can't change Keyv's behavior.
  • getMany, getRaw, getManyRaw catch store errors the way get does. They emit error, record stat:error, and return undefined values.
  • iterator follows the same rule. If the store fails mid-iteration, the iteration ends when a listener is attached, and rejects when none is.
  • Stats: a failed read counts as an error, not a miss. All four read methods, including get, record stat:error only, which matches the documented meaning of stat:miss.
  • @keyv/redis:
    • createKeyv and createKeyvNonBlocking no longer set keyv.throwOnErrors. Those assignments never changed behavior.
    • The adapter reports each failure once. When it rejects because of throwOnErrors or throwOnConnectError, it no longer also emits error. Before, a Keyv listener got the forwarded event and then the rejection, so it was called twice.
    • A failed connect rejects with the connection error as its cause.
  • Docs:
    • Keyv README: a new "Error Handling" section covers the rule, the fallback value for each method, and adapter errors that arrive outside any call. The throwOnErrors sections are removed. The adapter contract now asks adapters to either reject or emit, not both.
    • v5 to v6 migration guide: a new "Error Handling Changed and throwOnErrors Was Removed" section, with a quick-guide item. It explains how v5 behaved, method by method, including the methods whose behavior depended on the adapter, and what to change.
    • Website: the events-and-errors page gets a new "When errors throw" section. The throwOnErrors entries are removed from the options and properties pages.
    • Redis README: the error-handling section is rewritten, and its v5-to-v6 notes cover the single-report change.

Breaking changes

  • TypeScript users who pass throwOnErrors: the option no longer exists, so passing it is a type error. JavaScript callers see no change, because the option never took effect with a listener attached. Without one, calls already rejected.
  • Direct @keyv/redis users with an adapter-level error listener: when the adapter rejects, the listener no longer receives that failure too. The rejection carries it.

Verification

  • pnpm test in core/keyv passes: lint, 330 tests, and the same coverage as main. The only partial branches are the four that main already has.
  • Redis: all 12 non-cluster, non-sentinel test files pass against a local Redis 7, 207 tests including the shared test suite. cluster.test.ts and sentinel.test.ts need services that aren't available locally, so CI covers them. Biome is clean. tsc reports the same 6 client-typing errors in src/index.ts as main.
  • The new core tests for stats and iterator, and the three new Redis tests, fail on the previous commit and pass on this one.
  • tsc passes for core/keyv src. The changed test files add no type errors.
  • pnpm website:build succeeds. The new anchors exist, and the links from the migration guide, the events page, and the READMEs resolve.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X5LJCvt3pkR7FtfyAdzg5x


Generated by Claude Code

throwOnErrors never did what it promised. Keyv passed it to Hookified as
throwOnEmitError, which Hookified only reads when an error event has no
listeners, and Keyv already throws in that case. It could not be made to
work across adapters either: most adapters catch their own failures,
emit error, and return a fallback value, so the option would have needed
a throw mode in each of them.

Keyv now follows the Node.js EventEmitter rule and nothing else. When an
operation fails, Keyv emits error. With a listener attached, the call
returns a fallback value. With none, it rejects. The throwOnErrors option,
getter, setter, and type are removed, and Keyv no longer passes a throw
setting to Hookified.

getMany, getRaw, and getManyRaw now catch store errors like get does. They
emit error, record stat:error, and return undefined values, so they follow
the same rule instead of rejecting even when a listener is attached.

@keyv/redis createKeyv and createKeyvNonBlocking no longer set the removed
option. The Keyv README, the website error, options, and properties pages,
the v5 to v6 migration guide, and the Redis README now describe the rule,
the fallback values, and what changed from v5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5LJCvt3pkR7FtfyAdzg5x
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T19:03:12.265395Z f90f62f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4068b0a) to head (d232b6e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2155   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines         5284      5283    -1     
  Branches       857       852    -5     
=========================================
- Hits          5284      5283    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f90f62f39b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread website/site/docs/migration/v5-to-v6.md Resolved
Comment thread core/keyv/src/keyv.ts Resolved
Comment thread core/keyv/src/keyv.ts Resolved
Comment thread website/site/docs/migration/v5-to-v6.md Resolved
Addresses the review findings on the listener rule:

- iterator() follows the rule. When the store fails mid-iteration, Keyv
  emits error and records stat:error, then ends the iteration if a
  listener is attached, or rejects if none is.
- A failed read no longer counts as a miss. get, getMany, getRaw, and
  getManyRaw record stat:error only, which matches the documented meaning
  of stat:miss: a missing or expired key.
- @keyv/redis reports each failure once. When it rejects because of
  throwOnErrors or throwOnConnectError, it no longer also emits error.
  Keyv forwards the adapter's error events, so a Keyv listener was called
  twice for one failure. A failed connect now rejects with the connection
  error as its cause instead of emitting it first.
- The migration guide's v5 table now shows that has, hasMany, getMany,
  and getManyRaw depended on whether the adapter had its own version of
  the method, and that iterator rejected.
- The docs cover iterator's fallback, how failed reads count in stats,
  and the adapter rule to either reject or emit, not both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5LJCvt3pkR7FtfyAdzg5x
@jaredwray
jaredwray merged commit 860dba7 into main Sep 26, 2026
16 checks passed
@jaredwray
jaredwray deleted the claude/wizardly-lamport-lyi7hy branch September 26, 2026 06:38
@jaredwray jaredwray mentioned this pull request Oct 4, 2026
8 of 10 tasks
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