Skip to content

Raise a helpful ArgumentError for non-hash context - #226

Open
ouchinao wants to merge 1 commit into
collectiveidea:masterfrom
ouchinao:friendly-error-for-non-hash-context
Open

Raise a helpful ArgumentError for non-hash context#226
ouchinao wants to merge 1 commit into
collectiveidea:masterfrom
ouchinao:friendly-error-for-non-hash-context

Conversation

@ouchinao

@ouchinao ouchinao commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Fixes #178.

Calling an interactor with a non-hash argument — e.g. MyInteractor.call(something) instead of MyInteractor.call(something: "value") — currently fails deep inside OpenStruct with a cryptic error:

undefined method `each_pair' for #MyInteractor:0x00007fa2fc407350

This gives no hint about what actually went wrong. With this change, Context.build raises an ArgumentError that points directly at the likely mistake:

ArgumentError: Expected a Hash or an object responding to #each_pair,
got MyInteractor. Did you mean to pass keyword arguments?
(e.g. MyInteractor.call(foo: "bar"))

Behavior

  • An existing Interactor::Context is preserved, as before
  • nil and any object responding to #each_pair (Hash, HashWithIndifferentAccess, etc.) are accepted, as before — no breaking change for valid usage
  • Anything else now raises the descriptive ArgumentError instead of a confusing NoMethodError

Testing

  • Added specs for the nil case, #each_pair-responding objects, and the new error
  • Full suite passes: 113 examples, 0 failures
  • standardrb passes

gif

Passing a non-hash argument to `.call` previously failed with a cryptic
"undefined method `each_pair'" error. Context.build now raises an
ArgumentError explaining that keyword arguments were likely intended.

nil and any object responding to #each_pair are still accepted.

Closes collectiveidea#178

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Friendly error message when calling interactor with non-hash arguments

1 participant