mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: remove field name from string length error message (#594)
* fix: remove field name from string length error message * fix: remove old unused `Error.Changes.UnknownError` * fix: do not capitalize ash error messages * fix: change error kind code for `Ash.Error.Forbidden.Policy`
This commit is contained in:
parent
2384d35eea
commit
adb6cefac1
12 changed files with 37 additions and 54 deletions
|
@ -443,7 +443,7 @@ defmodule Ash.Actions.ManagedRelationships do
|
|||
|> Ash.Changeset.add_error(
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Changes would create a new related record"
|
||||
message: "changes would create a new related record"
|
||||
)
|
||||
)
|
||||
|> Ash.Changeset.put_context(:private, %{
|
||||
|
@ -1082,7 +1082,7 @@ defmodule Ash.Actions.ManagedRelationships do
|
|||
{:error,
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Changes would create a new related record"
|
||||
message: "changes would create a new related record"
|
||||
)}
|
||||
end
|
||||
|
||||
|
@ -1236,7 +1236,7 @@ defmodule Ash.Actions.ManagedRelationships do
|
|||
{:error,
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Changes would update a record"
|
||||
message: "changes would update a record"
|
||||
)}
|
||||
|
||||
:ignore ->
|
||||
|
@ -1621,7 +1621,7 @@ defmodule Ash.Actions.ManagedRelationships do
|
|||
{:error,
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Changes would destroy a record"
|
||||
message: "changes would destroy a record"
|
||||
)}}
|
||||
|
||||
{:unrelate, action_name} ->
|
||||
|
|
|
@ -496,7 +496,7 @@ defmodule Ash.Actions.Read do
|
|||
|
||||
%Ash.Query.Ref{attribute: %Ash.Resource.Calculation{}} = ref ->
|
||||
raise Ash.Error.Framework.AssumptionFailed,
|
||||
message: "Unhandled calculation in filter statement #{inspect(ref)}"
|
||||
message: "unhandled calculation in filter statement #{inspect(ref)}"
|
||||
|
||||
%Ash.Query.Ref{attribute: %Ash.Query.Calculation{} = calc} = ref ->
|
||||
%{
|
||||
|
@ -1738,7 +1738,7 @@ defmodule Ash.Actions.Read do
|
|||
)
|
||||
else
|
||||
raise Ash.Error.Framework.AssumptionFailed,
|
||||
message: "Only calculation & relationship deps should have input"
|
||||
message: "only calculation & relationship deps should have input"
|
||||
end
|
||||
|
||||
%Ash.Query.Calculation{} = calculation ->
|
||||
|
@ -1785,7 +1785,7 @@ defmodule Ash.Actions.Read do
|
|||
true ->
|
||||
raise Ash.Error.Framework.AssumptionFailed,
|
||||
message:
|
||||
"Only attribute & aggregate deps should remain at this point. Got #{inspect(other)} on #{inspect(query.resource)}"
|
||||
"only attribute & aggregate deps should remain at this point, got #{inspect(other)} on #{inspect(query.resource)}"
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -2625,7 +2625,7 @@ defmodule Ash.Changeset do
|
|||
error =
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Relationship is not editable"
|
||||
message: "relationship is not editable"
|
||||
)
|
||||
|
||||
add_error(changeset, error)
|
||||
|
@ -2634,7 +2634,7 @@ defmodule Ash.Changeset do
|
|||
error =
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Cannot manage a manual relationship"
|
||||
message: "cannot manage a manual relationship"
|
||||
)
|
||||
|
||||
add_error(changeset, error)
|
||||
|
@ -2643,7 +2643,7 @@ defmodule Ash.Changeset do
|
|||
error =
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Cannot manage a #{type} relationship with a list of records"
|
||||
message: "cannot manage a #{type} relationship with a list of records"
|
||||
)
|
||||
|
||||
add_error(changeset, error)
|
||||
|
@ -2707,7 +2707,7 @@ defmodule Ash.Changeset do
|
|||
changeset,
|
||||
InvalidRelationship.exception(
|
||||
relationship: relationship.name,
|
||||
message: "Cannot provide structs that don't match the destination"
|
||||
message: "cannot provide structs that don't match the destination"
|
||||
)
|
||||
)
|
||||
else
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
defmodule Ash.Error.Changes.UnknownError do
|
||||
@moduledoc "Used when a change fails for an unknown reason"
|
||||
use Ash.Error.Exception
|
||||
|
||||
def_ash_error([:field, :error], class: :invalid)
|
||||
|
||||
defimpl Ash.ErrorKind do
|
||||
def id(_), do: Ash.UUID.generate()
|
||||
|
||||
def code(_), do: "unknown_change_error"
|
||||
|
||||
def message(%{field: field, error: error}) do
|
||||
"Unknown error for change on field #{field}: #{inspect(error)}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -407,6 +407,6 @@ defmodule Ash.Error.Forbidden.Policy do
|
|||
end
|
||||
end
|
||||
|
||||
def code(_), do: "forbidden"
|
||||
def code(_), do: "forbidden_by_policy"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2379,7 +2379,7 @@ defmodule Ash.Filter do
|
|||
InvalidFilterValue.exception(
|
||||
value: inspect(nested_statement),
|
||||
message:
|
||||
"A single value must be castable to the primary key of the resource: #{inspect(context.resource)}"
|
||||
"a single value must be castable to the primary key of the resource: #{inspect(context.resource)}"
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
@ -2666,7 +2666,7 @@ defmodule Ash.Filter do
|
|||
Ash.Error.Query.InvalidExpression.exception(
|
||||
expression: expr,
|
||||
message:
|
||||
"Cannot access multiple resources for a data layer that can't be joined from within a single expression"
|
||||
"cannot access multiple resources for a data layer that can't be joined from within a single expression"
|
||||
)}
|
||||
end
|
||||
|
||||
|
@ -2674,7 +2674,7 @@ defmodule Ash.Filter do
|
|||
{:error,
|
||||
Ash.Error.Query.InvalidExpression.exception(
|
||||
expression: expr,
|
||||
message: "Cannot access multiple data layers within a single expression"
|
||||
message: "cannot access multiple data layers within a single expression"
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ defmodule Ash.Resource.Change.RelateActor do
|
|||
changeset,
|
||||
InvalidRelationship.exception(
|
||||
relationship: opts[:relationship],
|
||||
message: "Could not relate to actor, as no actor was found (and :allow_nil? is false)"
|
||||
message: "could not relate to actor, as no actor was found (and :allow_nil? is false)"
|
||||
)
|
||||
)
|
||||
end
|
||||
|
|
|
@ -179,7 +179,7 @@ defmodule Ash.Resource.Validation.Builtins do
|
|||
|
||||
validate numericality(:age, greater_than_or_equal_to: 18),
|
||||
where: [attribute_equals(:show_adult_content, true)],
|
||||
message: "Must be over %{greater_than_or_equal_to} to enable adult content."
|
||||
message: "must be over %{greater_than_or_equal_to} to enable adult content."
|
||||
|
||||
validate numericality(:points, greater_than: 0, less_than_or_equal_to: 100)
|
||||
"""
|
||||
|
|
|
@ -42,7 +42,7 @@ defmodule Ash.Resource.Validation.Confirm do
|
|||
InvalidAttribute.exception(
|
||||
field: opts[:confirmation],
|
||||
value: confirmation_value,
|
||||
message: "Confirmation did not match value"
|
||||
message: "confirmation did not match value"
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,8 +37,7 @@ defmodule Ash.Resource.Validation.StringLength do
|
|||
InvalidAttribute.exception(
|
||||
value: value,
|
||||
field: opts[:attribute],
|
||||
message: "%{field} could not be parsed",
|
||||
vars: [field: opts[:attribute]]
|
||||
message: "could not be parsed"
|
||||
)}
|
||||
end
|
||||
|
||||
|
@ -60,8 +59,8 @@ defmodule Ash.Resource.Validation.StringLength do
|
|||
InvalidAttribute.exception(
|
||||
value: value,
|
||||
field: opts[:attribute],
|
||||
message: "%{field} must have length of exactly %{exact}",
|
||||
vars: [field: opts[:attribute], exact: exact]
|
||||
message: "must have length of exactly %{exact}",
|
||||
vars: [exact: exact]
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
@ -76,8 +75,8 @@ defmodule Ash.Resource.Validation.StringLength do
|
|||
InvalidAttribute.exception(
|
||||
value: value,
|
||||
field: opts[:attribute],
|
||||
message: "%{field} must have length of between %{min} and %{max}",
|
||||
vars: [field: opts[:attribute], min: min, max: max]
|
||||
message: "must have length of between %{min} and %{max}",
|
||||
vars: [min: min, max: max]
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
@ -90,8 +89,8 @@ defmodule Ash.Resource.Validation.StringLength do
|
|||
InvalidAttribute.exception(
|
||||
value: value,
|
||||
field: opts[:attribute],
|
||||
message: "%{field} must have length of at least %{min}",
|
||||
vars: [field: opts[:attribute], min: min]
|
||||
message: "must have length of at least %{min}",
|
||||
vars: [min: min]
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
@ -104,8 +103,8 @@ defmodule Ash.Resource.Validation.StringLength do
|
|||
InvalidAttribute.exception(
|
||||
value: value,
|
||||
field: opts[:attribute],
|
||||
message: "%{field} must have length of no more than %{max}",
|
||||
vars: [field: opts[:attribute], max: max]
|
||||
message: "must have length of no more than %{max}",
|
||||
vars: [max: max]
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -519,7 +519,7 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
post2 = %{title: "title"}
|
||||
|
||||
assert_raise Ash.Error.Invalid,
|
||||
~r/Invalid value provided for posts: Changes would create a new related record/,
|
||||
~r/Invalid value provided for posts: changes would create a new related record/,
|
||||
fn ->
|
||||
Author
|
||||
|> Changeset.new()
|
||||
|
@ -786,7 +786,7 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
)
|
||||
|
||||
assert [%Ash.Error.Changes.InvalidRelationship{} = relation_error] = changeset.errors
|
||||
assert relation_error.message =~ "Cannot provide structs that don't match the destination"
|
||||
assert relation_error.message =~ "cannot provide structs that don't match the destination"
|
||||
end
|
||||
|
||||
test "it returns error if relationship does not exists" do
|
||||
|
@ -872,7 +872,7 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
end
|
||||
|
||||
test "arguments can be used in invalid changes" do
|
||||
assert_raise Ash.Error.Invalid, ~r/Confirmation did not match value/, fn ->
|
||||
assert_raise Ash.Error.Invalid, ~r/confirmation did not match value/, fn ->
|
||||
Category
|
||||
|> Changeset.new(%{"name" => "foo"})
|
||||
|> Changeset.set_argument(:confirm_name, "bar")
|
||||
|
@ -904,7 +904,7 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
%Ash.Error.Changes.InvalidAttribute{
|
||||
class: :invalid,
|
||||
field: :confirm_name,
|
||||
message: "Confirmation did not match value",
|
||||
message: "confirmation did not match value",
|
||||
path: []
|
||||
}
|
||||
] =
|
||||
|
|
|
@ -25,7 +25,7 @@ defmodule Ash.Test.Resource.Validation.StringLengthTest do
|
|||
{:ok, opts} = StringLength.init(attribute: :body, min: 3)
|
||||
changeset = Ash.Changeset.new(Post, %{body: "no"})
|
||||
|
||||
assert_error(changeset, opts, "body must have length of at least 3")
|
||||
assert_error(changeset, opts, "must have length of at least 3")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -41,7 +41,7 @@ defmodule Ash.Test.Resource.Validation.StringLengthTest do
|
|||
{:ok, opts} = StringLength.init(attribute: :body, max: 3)
|
||||
changeset = Ash.Changeset.new(Post, %{body: "invalid"})
|
||||
|
||||
assert_error(changeset, opts, "body must have length of no more than 3")
|
||||
assert_error(changeset, opts, "must have length of no more than 3")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -57,10 +57,10 @@ defmodule Ash.Test.Resource.Validation.StringLengthTest do
|
|||
{:ok, opts} = StringLength.init(attribute: :body, exact: 3)
|
||||
|
||||
changeset = Ash.Changeset.new(Post, %{body: "no"})
|
||||
assert_error(changeset, opts, "body must have length of exactly 3")
|
||||
assert_error(changeset, opts, "must have length of exactly 3")
|
||||
|
||||
changeset = Ash.Changeset.new(Post, %{body: "invalid"})
|
||||
assert_error(changeset, opts, "body must have length of exactly 3")
|
||||
assert_error(changeset, opts, "must have length of exactly 3")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -76,10 +76,10 @@ defmodule Ash.Test.Resource.Validation.StringLengthTest do
|
|||
{:ok, opts} = StringLength.init(attribute: :body, min: 2, max: 4)
|
||||
|
||||
changeset = Ash.Changeset.new(Post, %{body: "n"})
|
||||
assert_error(changeset, opts, "body must have length of between 2 and 4")
|
||||
assert_error(changeset, opts, "must have length of between 2 and 4")
|
||||
|
||||
changeset = Ash.Changeset.new(Post, %{body: "invalid"})
|
||||
assert_error(changeset, opts, "body must have length of between 2 and 4")
|
||||
assert_error(changeset, opts, "must have length of between 2 and 4")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue