Change error class from TypeError
to TypeStruct::MultiTypeError
on from_hash
with other object than Hash
#16
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.
I have suggestions
This PR proposes changing the exception raised in the
TypeStruct#from_hash
method fromTypeError
toTypeStruct::MultiTypeError
when the input is not aHash
object.Background
The
TypeStruct#from_hash
method is used to construct aTypeStruct
from aHash
object. In scenarios such as with Ruby on Rails controllers handling invalid JSON requests, the current implementation raises aTypeError
when a non-Hash object is passed. ThisTypeError
is widely used across different contexts.Example
Current behavior in Ruby on Rails:
Solution
By changing
TypeStruct::MultiTypeError
, we can provide more specific error messages that detail the nature of the type mismatch, improving error traceability and specificity. This enhancement aids developers in pinpointing the exact nature of the issue, making debugging more straightforward and enhancing overall code maintainability.Proposed changes in error handling:
Note
I believe this improvement will significantly benefit our project by making error handling more intuitive and debugging processes more efficient. If you agree with these changes, I kindly ask for your review and approval to merge this pull request.
Thank you for considering this enhancement.