Narrow Generator#schema_columns' rescue to ActiveRecordError - #80
Merged
Merged
Conversation
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>
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.
The bug
Permittable::ColumnGuard.schema_reachable?deliberately scopes its rescue toActiveRecord::ActiveRecordError(with adefined?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 (NameErrorfrom a typo, etc.) must keep surfacing.Generator#schema_columnsdid not follow the same philosophy. It used a blanketrescue StandardErroraroundmodel.table_exists?/model.columns, swallowing any error and returningnil. A broken custom type adapter, or a genuine app bug thatColumnGuard.schema_reachable?would loudly raise at controller-load time, instead madepermittable:generatequietly fall back to "no columns" and emit a degraded/empty draft with no error — masking exactly the class of bugcolumn_guard.rbwas written to surface.The fix
Narrow
schema_columns' rescue to matchschema_reachable?exactly, including thedefined?(ActiveRecord::ActiveRecordError)guard (this gem's only runtime dependency is activesupport;model:is duck-typed so the gem stays loadable without activerecord at all):A genuinely unreachable schema (e.g.
model.columnsraisingActiveRecord::StatementInvalidfor a missing table — already covered by an existing spec) still degrades tonilcolumns, exactly as before. Anything else now propagates instead of being silently swallowed.Verification
spec/generator_spec.rb): stubs.columnsto raise aNoMethodError(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 failuresbundle exec rubocop lib/permittable/generator.rb spec/generator_spec.rb— no offenses🤖 Generated with Claude Code