Skip to content

Raise an actionable error when a cache predates a coder#65

Open
navidemad wants to merge 1 commit into
Gusto:mainfrom
navidemad:friendlier-missing-coder-data-error
Open

Raise an actionable error when a cache predates a coder#65
navidemad wants to merge 1 commit into
Gusto:mainfrom
navidemad:friendlier-missing-coder-data-error

Conversation

@navidemad
Copy link
Copy Markdown

Summary

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, 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 both Cache#load (mount) and Cache#evaluate (parent data), so either path can hit it.

Change

Replace the bare fetch with a fetch block that raises a new FixtureKit::MissingCoderDataError, naming the coder and pointing at cache regeneration:

The fixture cache has no data for FixtureKit::SomeCoder. This usually means
the cache was written before FixtureKit::SomeCoder was registered as a coder.
Regenerate the fixture cache so it includes this coder (clear the cache
directory, or run without FIXTURE_KIT_PRESERVE_CACHE=1).

Same fail-loud, stale-cache-hint approach the foreign-key check in ActiveRecordCoder#mount already uses.

Test plan

  • bundle exec rspec spec/unit/memory_cache_spec.rb
  • bundle exec rspec (full suite)

`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`.
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