chore: update dialyzer & cleanup dead code

This commit is contained in:
Zach Daniel 2023-10-21 23:30:33 -04:00
parent 63dbf2603f
commit 7eac076581
8 changed files with 19 additions and 29 deletions

View file

@ -54,19 +54,6 @@ defmodule Ash.Error do
@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
def error_modules, do: Keyword.values(@error_modules)
@ -207,7 +194,7 @@ defmodule Ash.Error do
- `query`: a query related to 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(%struct{errors: errors} = thing, opts)

View file

@ -5,6 +5,8 @@ defmodule Ash.Error.Forbidden do
def_ash_error([:errors, stacktraces?: true], class: :forbidden)
@type t :: %__MODULE__{}
defimpl Ash.ErrorKind do
def id(_), do: Ash.UUID.generate()

View file

@ -4,6 +4,8 @@ defmodule Ash.Error.Framework do
def_ash_error([:errors, stacktraces?: true], class: :framework)
@type t :: %__MODULE__{}
defimpl Ash.ErrorKind do
def id(_), do: Ash.UUID.generate()

View file

@ -4,6 +4,8 @@ defmodule Ash.Error.Invalid do
def_ash_error([:errors, stacktraces?: true], class: :invalid)
@type t :: %__MODULE__{}
defimpl Ash.ErrorKind do
def id(_), do: Ash.UUID.generate()

View file

@ -4,6 +4,8 @@ defmodule Ash.Error.Unknown do
def_ash_error([:errors, stacktraces?: true], class: :unknown)
@type t :: %__MODULE__{}
def exception(opts) do
if opts[:error] do
super(Keyword.update(opts, :errors, [opts[:error]], &[opts[:error] | &1]))

View file

@ -14,7 +14,7 @@ defmodule Ash.Test do
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
error_class :: Ash.Error.class_module(),
(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
type =
case changeset_query_or_input do
@ -32,7 +32,9 @@ defmodule Ash.Test do
)
end
ExUnit.Assertions.assert(Enum.any?(error.errors, callback),
match = Enum.find(error.errors, callback)
ExUnit.Assertions.assert(match,
message:
opts[:message] ||
"""
@ -43,6 +45,8 @@ defmodule Ash.Test do
#{inspect(error.errors, pretty: true)}
"""
)
match
end
@doc """
@ -54,7 +58,7 @@ defmodule Ash.Test do
Ash.Changeset.t() | Ash.Query.t() | Ash.ActionInput.t(),
error_class :: Ash.Error.class_module(),
(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
type =
case changeset_query_or_input do
@ -89,6 +93,8 @@ defmodule Ash.Test do
#{inspect(error.errors, pretty: true)}
"""
)
match
end
@doc """

View file

@ -19,7 +19,7 @@ defmodule Ash.MixProject do
elixirc_paths: elixirc_paths(Mix.env()),
package: package(),
deps: deps(),
dialyzer: [plt_add_apps: [:mix, :mnesia, :earmark, :plug]],
dialyzer: [plt_add_apps: [:mix, :mnesia, :earmark, :plug, :ex_unit]],
docs: docs(),
aliases: aliases(),
description: @description,

View file

@ -1,6 +1,5 @@
defmodule Ash.Test.CodeInterfaceTest do
@moduledoc false
alias Ash.Error.Exception
use ExUnit.Case, async: true
defmodule User do
@ -122,16 +121,6 @@ defmodule Ash.Test.CodeInterfaceTest do
end
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,
~r/^Initial must be a changeset with the action type of.+/i,
fn ->