Skip to content

Narrow Generator#schema_columns' rescue to ActiveRecordError - #80

Merged
VSN2015 merged 1 commit into
masterfrom
fix/generator-schema-columns-rescue
Sep 29, 2026
Merged

VSN2015 merged 1 commit into
masterfrom
fix/generator-schema-columns-rescue

Conversation

@VSN2015

@VSN2015 VSN2015 commented Sep 28, 2026

Copy link
Copy Markdown
Owner

The bug

Permittable::ColumnGuard.schema_reachable? deliberately scopes its rescue to ActiveRecord::ActiveRecordError (with a defined? guard so the gem stays loadable without activerecord) — its own comment states the intent plainly: a genuinely unreachable schema (no database yet, table not migrated) degrades gracefully, but a real bug (NameError from a typo, etc.) must keep surfacing.

Generator#schema_columns did not follow the same philosophy. It used a blanket rescue StandardError around model.table_exists?/model.columns, swallowing any error and returning nil. A broken custom type adapter, or a genuine app bug that ColumnGuard.schema_reachable? would loudly raise at controller-load time, instead made permittable:generate quietly fall back to "no columns" and emit a degraded/empty draft with no error — masking exactly the class of bug column_guard.rb was written to surface.

The fix

Narrow schema_columns' rescue to match schema_reachable? exactly, including the defined?(ActiveRecord::ActiveRecordError) guard (this gem's only runtime dependency is activesupport; model: is duck-typed so the gem stays loadable without activerecord at all):

rescue StandardError => e
  raise unless defined?(ActiveRecord::ActiveRecordError) && e.is_a?(ActiveRecord::ActiveRecordError)

  nil
end

A genuinely unreachable schema (e.g. model.columns raising ActiveRecord::StatementInvalid for a missing table — already covered by an existing spec) still degrades to nil columns, exactly as before. Anything else now propagates instead of being silently swallowed.

Verification

  • New test written first (spec/generator_spec.rb): stubs .columns to raise a NoMethodError (standing in for a broken custom type adapter) and asserts it propagates instead of drafting an empty contract. Confirmed to fail before the implementation change and pass after.
  • bundle exec rspec — 852 examples, 0 failures
  • bundle exec rubocop lib/permittable/generator.rb spec/generator_spec.rb — no offenses

🤖 Generated with Claude Code

Generator#schema_columns caught StandardError, so a broken custom
type adapter or any other real bug in model.table_exists?/.columns
was swallowed and permittable:generate silently emitted a degraded,
column-less draft instead of raising. ColumnGuard.schema_reachable?
already scopes its equivalent rescue to
ActiveRecord::ActiveRecordError specifically so a real bug keeps
surfacing; schema_columns now matches it, including the same
defined?-guard so the gem stays loadable in a host without
activerecord.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@VSN2015
VSN2015 merged commit 78650af into master Sep 29, 2026
16 checks passed
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