Skip to content

Commit

Permalink
Document error message interpolation (#3538)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanl committed Jan 14, 2021
1 parent f832a27 commit 9649486
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/ecto/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 1617,7 @@ defmodule Ecto.Changeset do
An additional keyword list `keys` can be passed to provide additional
contextual information for the error. This is useful when using
`traverse_errors/2`
`traverse_errors/2` and when translating errors with `Gettext`
## Examples
Expand All @@ -1634,6 1634,13 @@ defmodule Ecto.Changeset do
[title: {"empty", [additional: "info"]}]
iex> changeset.valid?
false
iex> changeset = change(%Post{}, %{tags: ["ecto", "elixir", "x"]})
iex> changeset = add_error(changeset, :tags, "tag '%{val}' is too short", val: "x")
iex> changeset.errors
[tags: {"tag '%{val}' is too short", [val: "x"]}]
iex> changeset.valid?
false
"""
@spec add_error(t, atom, String.t, Keyword.t) :: t
def add_error(%Changeset{errors: errors} = changeset, key, message, keys \\ []) when is_binary(message) do
Expand Down

0 comments on commit 9649486

Please sign in to comment.