Zoi.Context (Zoi v0.5.5)
View SourceThe Context provides the parsing information such as the input data, parsed data and errors.
The context is passed around during the parsing process to keep track of the current state of parsing. It contains the schema being parsed, the input data, the parsed data, the path of the current error and any errors that have occurred during parsing.
Summary
Functions
Add a error to the context.
Types
@type error() :: Zoi.Error.t() | binary() | [Zoi.Error.t()]
@type t() :: %Zoi.Context{ errors: [Zoi.Error.t()], input: Zoi.input(), parsed: Zoi.input(), path: Zoi.Error.path(), schema: Zoi.Type.t() }
Functions
Add a error to the context.
Example
iex> schema = Zoi.string() |> Zoi.refine(fn input, ctx ->
...> if String.length(input) > 5 do
...> :ok
...> else
...> Zoi.Context.add_error(ctx, %Zoi.Error{message: "Input too long"})
...> end
...> end)
...> Zoi.parse(schema, "s")
{:error, [%Zoi.Error{message: "Input too long"}]}