mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
chore: update dialyzer & cleanup dead code
This commit is contained in:
parent
63dbf2603f
commit
7eac076581
8 changed files with 19 additions and 29 deletions
|
@ -54,19 +54,6 @@ defmodule Ash.Error do
|
||||||
|
|
||||||
@error_class_indices @error_classes |> Enum.with_index() |> Enum.into(%{})
|
@error_class_indices @error_classes |> Enum.with_index() |> Enum.into(%{})
|
||||||
|
|
||||||
@spec extract_errors(
|
|
||||||
t()
|
|
||||||
| list(t())
|
|
||||||
| Ash.Changeset.t()
|
|
||||||
| Ash.Query.t()
|
|
||||||
| Ash.ActionInput.t()
|
|
||||||
| term()
|
|
||||||
) :: [class_error()]
|
|
||||||
def extract_errors(%struct{errors: errors})
|
|
||||||
when struct in [Ash.Changeset, Ash.Query, Ash.ActionInput] do
|
|
||||||
Ash.Error.to_error_class(errors)
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def error_modules, do: Keyword.values(@error_modules)
|
def error_modules, do: Keyword.values(@error_modules)
|
||||||
|
|
||||||
|
@ -207,7 +194,7 @@ defmodule Ash.Error do
|
||||||
- `query`: a query related to the error
|
- `query`: a query related to the error
|
||||||
- `error_context`: a sting message providing extra context around the error
|
- `error_context`: a sting message providing extra context around the error
|
||||||
"""
|
"""
|
||||||
@spec to_error_class(term()) :: class_error()
|
@spec to_error_class(any()) :: class_error()
|
||||||
def to_error_class(values, opts \\ [])
|
def to_error_class(values, opts \\ [])
|
||||||
|
|
||||||
def to_error_class(%struct{errors: errors} = thing, opts)
|
def to_error_class(%struct{errors: errors} = thing, opts)
|
||||||
|
|
|
@ -5,6 +5,8 @@ defmodule Ash.Error.Forbidden do
|
||||||
|
|
||||||
def_ash_error([:errors, stacktraces?: true], class: :forbidden)
|
def_ash_error([:errors, stacktraces?: true], class: :forbidden)
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
defimpl Ash.ErrorKind do
|
defimpl Ash.ErrorKind do
|
||||||
def id(_), do: Ash.UUID.generate()
|
def id(_), do: Ash.UUID.generate()
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ defmodule Ash.Error.Framework do
|
||||||
|
|
||||||
def_ash_error([:errors, stacktraces?: true], class: :framework)
|
def_ash_error([:errors, stacktraces?: true], class: :framework)
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
defimpl Ash.ErrorKind do
|
defimpl Ash.ErrorKind do
|
||||||
def id(_), do: Ash.UUID.generate()
|
def id(_), do: Ash.UUID.generate()
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ defmodule Ash.Error.Invalid do
|
||||||
|
|
||||||
def_ash_error([:errors, stacktraces?: true], class: :invalid)
|
def_ash_error([:errors, stacktraces?: true], class: :invalid)
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
defimpl Ash.ErrorKind do
|
defimpl Ash.ErrorKind do
|
||||||
def id(_), do: Ash.UUID.generate()
|
def id(_), do: Ash.UUID.generate()
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ defmodule Ash.Error.Unknown do
|
||||||
|
|
||||||
def_ash_error([:errors, stacktraces?: true], class: :unknown)
|
def_ash_error([:errors, stacktraces?: true], class: :unknown)
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
def exception(opts) do
|
def exception(opts) do
|
||||||
if opts[:error] do
|
if opts[:error] do
|
||||||
super(Keyword.update(opts, :errors, [opts[:error]], &[opts[:error] | &1]))
|
super(Keyword.update(opts, :errors, [opts[:error]], &[opts[:error] | &1]))
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule Ash.Test do
|
||||||
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
|
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
|
||||||
error_class :: Ash.Error.class_module(),
|
error_class :: Ash.Error.class_module(),
|
||||||
(Ash.Error.t() -> boolean)
|
(Ash.Error.t() -> boolean)
|
||||||
) :: :ok | no_return
|
) :: Ash.Error.t() | no_return
|
||||||
def assert_has_error(changeset_query_or_input, error_class \\ nil, callback, opts \\ []) do
|
def assert_has_error(changeset_query_or_input, error_class \\ nil, callback, opts \\ []) do
|
||||||
type =
|
type =
|
||||||
case changeset_query_or_input do
|
case changeset_query_or_input do
|
||||||
|
@ -32,7 +32,9 @@ defmodule Ash.Test do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
ExUnit.Assertions.assert(Enum.any?(error.errors, callback),
|
match = Enum.find(error.errors, callback)
|
||||||
|
|
||||||
|
ExUnit.Assertions.assert(match,
|
||||||
message:
|
message:
|
||||||
opts[:message] ||
|
opts[:message] ||
|
||||||
"""
|
"""
|
||||||
|
@ -43,6 +45,8 @@ defmodule Ash.Test do
|
||||||
#{inspect(error.errors, pretty: true)}
|
#{inspect(error.errors, pretty: true)}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
match
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -54,7 +58,7 @@ defmodule Ash.Test do
|
||||||
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
|
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
|
||||||
error_class :: Ash.Error.class_module(),
|
error_class :: Ash.Error.class_module(),
|
||||||
(Ash.Error.t() -> boolean)
|
(Ash.Error.t() -> boolean)
|
||||||
) :: :ok | no_return
|
) :: Ash.Error.t() | no_return
|
||||||
def refute_has_error(changeset_query_or_input, error_class \\ nil, callback, opts \\ []) do
|
def refute_has_error(changeset_query_or_input, error_class \\ nil, callback, opts \\ []) do
|
||||||
type =
|
type =
|
||||||
case changeset_query_or_input do
|
case changeset_query_or_input do
|
||||||
|
@ -89,6 +93,8 @@ defmodule Ash.Test do
|
||||||
#{inspect(error.errors, pretty: true)}
|
#{inspect(error.errors, pretty: true)}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
match
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -19,7 +19,7 @@ defmodule Ash.MixProject do
|
||||||
elixirc_paths: elixirc_paths(Mix.env()),
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
package: package(),
|
package: package(),
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
dialyzer: [plt_add_apps: [:mix, :mnesia, :earmark, :plug]],
|
dialyzer: [plt_add_apps: [:mix, :mnesia, :earmark, :plug, :ex_unit]],
|
||||||
docs: docs(),
|
docs: docs(),
|
||||||
aliases: aliases(),
|
aliases: aliases(),
|
||||||
description: @description,
|
description: @description,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
defmodule Ash.Test.CodeInterfaceTest do
|
defmodule Ash.Test.CodeInterfaceTest do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
alias Ash.Error.Exception
|
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
defmodule User do
|
defmodule User do
|
||||||
|
@ -122,16 +121,6 @@ defmodule Ash.Test.CodeInterfaceTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "code interface-generated functions should check the type of their first argument and return an expressive error" do
|
test "code interface-generated functions should check the type of their first argument and return an expressive error" do
|
||||||
# create a few users
|
|
||||||
users = [
|
|
||||||
User
|
|
||||||
|> Ash.Changeset.for_create(:create, %{first_name: "Zach", last_name: "Daniel"})
|
|
||||||
|> Api.create!(),
|
|
||||||
User
|
|
||||||
|> Ash.Changeset.for_create(:create, %{first_name: "Zach2", last_name: "Daniel2"})
|
|
||||||
|> Api.create!()
|
|
||||||
]
|
|
||||||
|
|
||||||
assert_raise ArgumentError,
|
assert_raise ArgumentError,
|
||||||
~r/^Initial must be a changeset with the action type of.+/i,
|
~r/^Initial must be a changeset with the action type of.+/i,
|
||||||
fn ->
|
fn ->
|
||||||
|
|
Loading…
Reference in a new issue