-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve TypeError identification by defining a custom error class #14
Comments
Thank you for your valuable suggestion. |
What I was actually trying to do was error handling in the Rails controller (e.g. responding to |
However, I don't have the motivation or resources to handle changes that are not compatible. |
Thank you for your consideration and response.
While I understand the challenges of handling changes that may impact compatibility, I'd like to propose a solution that minimizes such concerns. TypeConversionError = Class.new(TypeError) This approach allows for the introduction of the custom error class without compromising the existing usage of
Yes, it is. Consequently, having the ability to handle errors consistently in shared components like e.g. class ApplicationController
rescue_from TypeStruct::TypeConversionError do
# This is not graceful error message, but it is okay for internal purpose APIs.
render status: :unprocessoble_entity, json: { message: 'invalid_parameter' }
end
end |
That's a great idea. With that approach, Then I think it would be acceptable. "How cool is it that I'm always open to receiving a Pull Request. |
Thank you for acceptance of the idea and providing powerful gem. |
I have suggestions
It is challenging to distinguish whether a
TypeError
originated from the gem itself.To enhance the identification of errors originating from the type_struct gem, I propose defining a custom error class for type_struct-specific TypeError.
This would make it easier for users to identify and handle errors specifically related to the gem.
Changes
TypeConversionError
(for example), within your type_struct gem.TypeConversionError
class inherits fromstandard Ruby TypeError
.TypeConversionError
where appropriate.Benefits
Improved error handling:
Users can easily distinguish between
standard Ruby TypeError
andTypeConversionError
, facilitating more targeted and effective debugging.Example Usage
Note
This change does not affect the existing behavior for handling
standard Ruby TypeError
.Updated
The example of the error class name
TypeStructError
is too general.I have changed it on this issue to
TypeConversionError
as the example.The text was updated successfully, but these errors were encountered: