View Source DataSchema.CastFunctionError exception (data_schema v0.5.0)
An error for when a casting function does not return the correct data.
All casting functions get wrapped in a rescue
to catch any unexpected exceptions. This
lets us add more useful information about where the error occurred that the stack trace
cannot provide - mainly which field failed the casting.
We then raise using the original stacktrace and printing the captured error message.
Matching on Specific Exceptions
If a user wishes to capture specific exceptions as part of casting they may do so by
matching on the :wrapped_error
field. For example:
try do
DataSchema.to_struct(my_input, MySchema)
rescue
%DataSchema.CastFunctionError{wrapped_error: %RuntimeError{}} ->
Logger.error("Expected Runtime Error")
error ->
reraise error, __STACKTRACE__
end
Link to this section Summary
Functions
Creates an appropriate error message from the given struct.
Link to this section Functions
Creates an appropriate error message from the given struct.