Raise an actionable error when a cache predates a coder#65
Open
navidemad wants to merge 1 commit into
Open
Conversation
`MemoryCache#data_for` did a bare `data.fetch(coder_class)`, so when the on-disk cache had no entry for a registered coder it surfaced as an opaque `KeyError: key not found: FixtureKit::SomeCoder`. This happens when a coder is registered in the consuming process that was not registered when the cache was written — most commonly under `FIXTURE_KIT_PRESERVE_CACHE=1`, where a cache from a previous run is read by a process that has since added a coder. The lookup runs from both `Cache#load` (mount) and `Cache#evaluate` (parent data), so either path could hit it. Replace the bare fetch with a fetch block that raises `FixtureKit::MissingCoderDataError`, naming the coder and pointing at cache regeneration — same fail-loud, stale-cache-hint style as the foreign-key check in `ActiveRecordCoder#mount`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MemoryCache#data_fordid a baredata.fetch(coder_class), so when the on-disk cache had no entry for a registered coder it surfaced as an opaqueKeyError: key not found: FixtureKit::SomeCoder, with no hint about the cause or the fix.This happens when the consuming process has a coder registered that wasn't registered when the cache was written. The common case is
FIXTURE_KIT_PRESERVE_CACHE=1: a cache from a previous run gets read by a process that has since added a coder. The lookup runs from bothCache#load(mount) andCache#evaluate(parent data), so either path can hit it.Change
Replace the bare fetch with a
fetchblock that raises a newFixtureKit::MissingCoderDataError, naming the coder and pointing at cache regeneration:Same fail-loud, stale-cache-hint approach the foreign-key check in
ActiveRecordCoder#mountalready uses.Test plan
bundle exec rspec spec/unit/memory_cache_spec.rbbundle exec rspec(full suite)