View Source DataSchema.Errors (data_schema v0.3.1)
When we create a struct we either return the struct we were creating or we return this error. The error/errors that happened during struct creation are collected into this struct
Link to this section Summary
Types
An error is the struct key that caused the error and either an error message or a DataSchema.Errors struct in the case of nested error.
Functions
Adds an error to the given errors struct. The error is prepended to the list of current errors.
Returns an error tuple of the path to the problematic field and the error message.
Turns the DataSchema.Errors struct into a flattened error tuple of path to field and error message
Link to this section Types
Link to this section Functions
Adds an error to the given errors struct. The error is prepended to the list of current errors.
Returns an error tuple of the path to the problematic field and the error message.
Usually errors are returned as nested DataSchema.Errors
structs. This was to help
cater for the possibility of collecting all errors, but right now we stop casting as
soon as we error on a casting function, so errors are a little confusing. This function
can be used to return a flattened error.
Examples
iex> error = %DataSchema.Errors{
...> errors: [
...> comments: %DataSchema.Errors{
...> errors: [author:
...> %DataSchema.Errors{
...> errors: [name: "There was an error!"]
...> }
...> ]
...> }
...> ]
...> }
...> DataSchema.Errors.flatten_errors(error)
{[:comments, :author, :name], "There was an error!"}
Specs
to_error_tuple(t()) :: {:error, {path_to_error(), error_message()}}
Turns the DataSchema.Errors struct into a flattened error tuple of path to field and error message
Examples
iex> error = %DataSchema.Errors{
...> errors: [
...> comments: %DataSchema.Errors{
...> errors: [author:
...> %DataSchema.Errors{
...> errors: [name: "There was an error!"]
...> }
...> ]
...> }
...> ]
...> }
...> DataSchema.Errors.to_error_tuple(error)
{:error, {[:comments, :author, :name], "There was an error!"}}