Skip to content

fix: honor a Miss returned from the go() callback instead of wrapping it in a Hit#3

Merged
andrewshell merged 1 commit into
masterfrom
fix/honor-returned-miss
Jun 28, 2026
Merged

fix: honor a Miss returned from the go() callback instead of wrapping it in a Hit#3
andrewshell merged 1 commit into
masterfrom
fix/honor-returned-miss

Conversation

@andrewshell

Copy link
Copy Markdown
Owner

Summary

go() honored a returned Hit but wrapped every other return value — including a Miss — in a new Hit. A callback returning new Cacheism.Miss(...) to signal failure on an empty cache therefore produced a Hit whose .data was a Miss-shaped object (isHit === true while data.isMiss === true).

This adds a result instanceof Miss branch so a returned Miss is used as-is, symmetric with the existing returned-Hit handling:

if (result instanceof Hit) {
  response = result;
} else if (result instanceof Miss) {   // NEW
  response = result;
} else {
  response = new Hit(name, result);
}

The Miss is now persisted as a real Miss (preserving consecutiveErrors across the store round-trip) instead of a junk Hit.

Design note

A returned Miss is authoritative — it is not routed through the cacheOnFail/preferCache fallback to a stale cached Hit. That fallback stays exclusive to thrown errors. In short: a returned value is authoritative, while a throw delegates to the status policy.

Tests

Three new cases in test/memory.test.cjs (mirroring the existing "returns a Hit instance" block):

  • returned Miss used directly on an empty cache
  • returned Miss persisted, consecutiveErrors preserved through the store round-trip
  • under cacheOnFail, a returned Miss overwrites a cached Hit (pins the authoritative-vs-fallback decision)

Full suite: 82 pass, 0 fail; typecheck clean.

Docs

README gains a "Callback return value" subsection documenting return-vs-throw semantics and the new Cacheism.Miss(existing.cacheName, …) guidance, plus a clarifying note on the "Cache on Fail" status.

🤖 Generated with Claude Code

… it in a Hit

go() honored a returned Hit but wrapped every other return value, including a
Miss, in a new Hit. A callback returning new Cacheism.Miss(...) to signal
failure on an empty cache therefore produced a Hit whose data was a Miss-shaped
object (isHit true, data.isMiss true).

Add a `result instanceof Miss` branch so a returned Miss is used as-is,
symmetric with the existing returned-Hit handling. The Miss is persisted as a
real Miss, preserving consecutiveErrors across the store round-trip. A returned
Miss is authoritative and is not routed through the cacheOnFail/preferCache
fallback (that remains exclusive to thrown errors).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@andrewshell andrewshell merged commit 26046bc into master Jun 28, 2026
4 checks passed
@andrewshell andrewshell deleted the fix/honor-returned-miss branch June 28, 2026 15:31
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.

1 participant