amnesia
amnesia copied to clipboard
Dialyzer warnings when defining database
When running dialyzer
I can see 22 errors which comes from amnesia database definition. I have described all problems which I have found in amnesia
in one forum post. An workaround for this problem is available in this comment
Yep same here. A bit more background might be helpful.
In an umbrella application, some of our sub-apps depends on {:amnesia, "..."}
.
In the umbrella's mix.exs
file, we have something like this:
def project,
do: [
...,
dialyzer: [
plt_add_apps: [:mix, :xema, :json_xema],
plt_add_deps: :apps_direct,
flags: ["-Wunmatched_returns", :error_handling, :race_conditions, :underspecs]
],
....
]
Which works great for every single other dep.
Then we define our database such as:
use Amnesia
defdatabase TTCore.AmnesiaRepo do
deftable PersistedKV, [:name, :value], type: :set, copying: :disk do
@type t :: %PersistedKV{
name: String.t(),
value: any
}
end
end
From a clean slate, we now have 22 warnings as well. We've added rules to our dialyzer ignore list, but it's definitely not a long term option. What are we doing wrong?
Finding suitable PLTs
Checking PLT...
[:absinthe, :absinthe_phoenix, :absinthe_plug, :absinthe_relay, :amnesia, :asn1, :bamboo, :bcrypt_elixir, :certifi, :comeonin, :compiler, :connection, :conv_case, :corsica, :cowboy, :cowboy_telemetry, :cowlib, :crontab, :crypto, :dataloader, :db_connection, :decimal, :dymo, :ecto, :ecto_enum, :ecto_psql_extras, :ecto_sql, :eex, :eip_55, :elixir, :elixir_uuid, :entropy_string, :ethereumex, :ex_abi, :ex_cop, :ex_keccak, :ex_sha3, :exgravatar, :exq, :exq_ui, :exquisite, :faker, :gen_stage, :gettext, :guardian, :hackney, :html_entities, :httpoison, :idna, :inets, ...]
Looking up modules in dialyxir_erlang-22.3_elixir-1.11.2_deps-dev.plt
Finding applications for dialyxir_erlang-22.3_elixir-1.11.2_deps-dev.plt
Finding modules for dialyxir_erlang-22.3_elixir-1.11.2_deps-dev.plt
Checking 2200 modules in dialyxir_erlang-22.3_elixir-1.11.2_deps-dev.plt
Adding 658 modules to dialyxir_erlang-22.3_elixir-1.11.2_deps-dev.plt
done in 4m23.37s
No :ignore_warnings opt specified in mix.exs. Using default: .dialyzer_ignore.exs.
Starting Dialyzer
[
check_plt: false,
init_plt: 'whatever/_build/dev/dialyxir_erlang-22.3_elixir-1.11.2_deps-dev.plt',
files: ['whatever/_build/dev/lib/tt_core/ebin/Elixir.TTCore.Elections.Proposal.Query.beam',
'whatever/_build/dev/lib/tt_web/ebin/Elixir.TTWeb.Schema.Draftable.Draft.Mutations.beam',
'whatever/_build/dev/lib/tt_web/ebin/Elixir.TTWeb.Schema.Elections.Proposal.Types.beam',
'whatever/_build/dev/lib/tt_core/ebin/Elixir.TTCore.AmnesiaRepo.PersistedKV.beam',
'whatever/_build/dev/lib/tt_core/ebin/Elixir.TTCore.Taggable.Protocol.TTCore.Onboarding.Onboard.beam',
...],
warnings: [:unmatched_returns, :error_handling, :race_conditions, :underspecs,
...]
]
Total errors: 112, Skipped: 89, Unnecessary Skips: 0
done in 0m12.9s
:0:unknown_type
Unknown type: Amnesia.o/0.
________________________________________________________________________________
:0:unknown_type
Unknown type: Amnesia.Table.Selection.t/0.
________________________________________________________________________________
:0:unknown_type
Unknown type: Amnesia.Table.Stream.t/0.
________________________________________________________________________________
:0:unknown_type
Unknown type: Selection.t/0.
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:3:invalid_contract
The @spec for the function does not match the success typing of the function.
Function:
TTCore.AmnesiaRepo.create!/0
Success typing:
@spec create!() :: :ok
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:3:invalid_contract
The @spec for the function does not match the success typing of the function.
Function:
TTCore.AmnesiaRepo.create!/1
Success typing:
@spec create!(_) :: :ok
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:3:invalid_contract
The @spec for the function does not match the success typing of the function.
Function:
TTCore.AmnesiaRepo.destroy!/0
Success typing:
@spec destroy!() :: :ok
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:3:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.tables/0
Type specification:
@spec tables() :: [atom()]
Success typing:
@spec tables() :: [TTCore.AmnesiaRepo.PersistedKV, ...]
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:3:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.wait/1
Type specification:
@spec wait(integer() | :infinity) :: :ok | {:timeout, [atom()]} | {:error, atom()}
Success typing:
@spec wait(timeout()) :: :ok | {:error, atom()} | {:timeout, [atom()]}
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.database/0
Type specification:
@spec database() :: module()
Success typing:
@spec database() :: TTCore.AmnesiaRepo
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.delete/2
Type specification:
@spec delete(atom() | any(), t() | atom()) :: :ok | no_return()
Success typing:
@spec delete(_, :write | :write!) :: :ok
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.id/0
Type specification:
@spec id() :: atom()
Success typing:
@spec id() :: :name
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:extra_range
The type specification has too many types for the function.
Function:
TTCore.AmnesiaRepo.PersistedKV.lock/1
Extra type:
:ok
Success typing:
[atom()]
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.priority/1
Type specification:
@spec priority(integer()) :: Amnesia.Table.o()
Success typing:
@spec priority(non_neg_integer()) :: :ok | {:error, _}
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:pattern_match_cov
The pattern
variable_
can never match, because previous clauses completely cover the type
:undefined.
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:pattern_match_cov
The pattern
variable_
can never match, because previous clauses completely cover the type
:undefined.
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.select/1
Type specification:
@spec select(any()) :: Amnesia.Table.Selection.t() | nil | no_return()
Success typing:
@spec select([{atom() | tuple(), [any()], [any()]}]) :: nil | Amnesia.Table.Select.t()
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.select/2
Type specification:
@spec select(integer() | :read | :write, any()) :: Amnesia.Table.Selection.t() | nil | no_return()
Success typing:
@spec select(:read | :write | non_neg_integer(), [{atom() | tuple(), [any()], [any()]}]) ::
nil | Amnesia.Table.Select.t()
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:invalid_contract
The @spec for the function does not match the success typing of the function.
Function:
TTCore.AmnesiaRepo.PersistedKV.select/3
Success typing:
@spec select(:read | :write | non_neg_integer(), :read | :write | non_neg_integer(), [
{atom() | tuple(), [any()], [any()]}
]) :: nil | Amnesia.Table.Select.t()
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.select!/1
Type specification:
@spec select!(any()) :: Selection.t() | nil | no_return()
Success typing:
@spec select!([{atom() | tuple(), [any()], [any()]}]) :: nil | Amnesia.Table.Select.t()
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:contract_supertype
Type specification is a supertype of the success typing.
Function:
TTCore.AmnesiaRepo.PersistedKV.wait/1
Type specification:
@spec wait(integer() | :infinity) :: :ok | {:timeout, [atom()]} | {:error, atom()}
Success typing:
@spec wait(timeout()) :: :ok | {:error, atom()} | {:timeout, [atom()]}
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:pattern_match_cov
The pattern
variable_
can never match, because previous clauses completely cover the type
:undefined.
________________________________________________________________________________
lib/tt_core/amnesia_repo.ex:4:pattern_match_cov
The pattern
variable_
can never match, because previous clauses completely cover the type
:undefined.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2