Summary
Replace string raises with structured error classes and add respond_to_missing? to the extractors for better debugging and extension.
Problem
Opaque string errors
Errors today are plain strings:
raise "No comma format for class #{self.class} defined for style #{style}"
raise "Unknown data symbol #{arg.inspect}"
raise "Unknown header symbol #{arg.inspect}"
Callers cannot rescue Comma::UnknownStyle programmatically. Messages are fine for humans but fragile for apps that want to handle missing formats gracefully.
Locations:
lib/comma/object.rb
lib/comma/data_extractor.rb
lib/comma/header_extractor.rb
Missing respond_to_missing?
Both extractors use method_missing without respond_to_missing?. RuboCop excludes this via .rubocop_todo.yml (Style/MissingRespondToMissing).
That breaks expected Ruby semantics for introspection (respond_to?, IRB, some tooling).
Proposed approach
Define error hierarchy under Comma:
module Comma
class Error < StandardError; end
class UnknownStyle < Error; end
class UnknownColumnArgument < Error; end
class CircularStyleReference < Error; end # pairs with #1
end
Raise these with messages matching or improving current strings (backward compatible for string-matching rescues).
Add respond_to_missing? on both extractors delegating to the same rules as method_missing (always true for DSL method names inside a comma block context, or mirror method_missing behavior).
Files likely involved
- New:
lib/comma/errors.rb
lib/comma/object.rb
lib/comma/data_extractor.rb
lib/comma/header_extractor.rb
lib/comma/extractor.rb
- Specs asserting error type (can keep message assertions too)
Acceptance criteria
Labels (suggested)
refactor, enhancement
Depends on
Optional: #1 (CircularStyleReference error class)
Notes
Consider documenting rescuable errors in README/wiki in a follow-up; not required for this issue.
Summary
Replace string raises with structured error classes and add
respond_to_missing?to the extractors for better debugging and extension.Problem
Opaque string errors
Errors today are plain strings:
Callers cannot
rescue Comma::UnknownStyleprogrammatically. Messages are fine for humans but fragile for apps that want to handle missing formats gracefully.Locations:
lib/comma/object.rblib/comma/data_extractor.rblib/comma/header_extractor.rbMissing
respond_to_missing?Both extractors use
method_missingwithoutrespond_to_missing?. RuboCop excludes this via.rubocop_todo.yml(Style/MissingRespondToMissing).That breaks expected Ruby semantics for introspection (
respond_to?, IRB, some tooling).Proposed approach
Define error hierarchy under
Comma:Raise these with messages matching or improving current strings (backward compatible for string-matching rescues).
Add
respond_to_missing?on both extractors delegating to the same rules asmethod_missing(always true for DSL method names inside acommablock context, or mirrormethod_missingbehavior).Files likely involved
lib/comma/errors.rblib/comma/object.rblib/comma/data_extractor.rblib/comma/header_extractor.rblib/comma/extractor.rbAcceptance criteria
Comma::UnknownStyle(message still mentions class and style)Comma::UnknownColumnArgumentrespond_to_missing?implemented on both extractorsRuntimeErroror message strings updated intentionally (document in PR if message-only rescues exist in the wild)MissingRespondToMissingcan be removed for extractor filesLabels (suggested)
refactor,enhancementDepends on
Optional: #1 (
CircularStyleReferenceerror class)Notes
Consider documenting rescuable errors in README/wiki in a follow-up; not required for this issue.