'(ArgumentError) expected to: to be given as argument
Good day. I have weird ArgumentError in my code even tho the code looks very fine.
I'm Following the project from Mastering Elixirbook.
defmodule ElixirDrip.Storage.Provider do
@moduledoc false
@target Application.get_env(:elixir_drip, :storage_provider)
defdelegate upload(path, content), to: @target
defdelegate download(path), to: @target
end
The error
** (ArgumentError) expected to: to be given as argument
Solution 1:[1]
In the environment, you compile this code the :storage_provider is not set. You should have been warned about Application.get_env/3 on the module level should not be used (Application.compile_env/3 is to be used instead.)
Make sure you have the storage provider set in the environment you compile the code.
@target Application.compile_env(:elixir_drip, :storage_provider)
if is_nil(@target), do: raise "MUST BE SET: provider"
Solution 2:[2]
to: is supposed to be a module. I guess you need something like:
defdelegate upload(path, content), to: Application, as: :get_env
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aleksei Matiushkin |
| Solution 2 | bortzmeyer |
