ash-project / ash_postgres

The PostgreSQL data layer for Ash Framework
https://hexdocs.pm/ash_postgres
MIT License
139 stars 73 forks source link

Error when installing with Igniter - `Igniter.Project.Application.app_name/0 is undefined` #362

Open sevenseacat opened 3 months ago

sevenseacat commented 3 months ago

Describe the bug I've set up a new Phoenix app to test out Igniter setup, and run into an issue with AshPostgres.

==> phoenix_ecto
Compiling 7 files (.ex)
** (UndefinedFunctionError) function Igniter.Project.Application.app_name/0 is undefined (module Igniter.Project.Application is not available)
    (igniter 0.3.9) Igniter.Project.Application.app_name()
    (ash_postgres 2.1.15) lib/mix/tasks/ash_postgres.install.ex:10: Mix.Tasks.AshPostgres.Install.igniter/2
    (elixir 1.17.2) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
    (igniter 0.3.9) lib/igniter/util/install.ex:101: Igniter.Util.Install.run_installers/5

Upon re-running ash_postgres.install, the error does not appear, and everything works as normal?

To Reproduce

The library installs successfully, but the error occurs when it runs ash_postgres.install.

Expected behavior

ash_postgres.install should run successfully and patch my repo etc. files.

** Runtime

zachdaniel commented 3 months ago

Could it be something similar to this? https://elixirforum.com/t/mix-ash-gen-domain-function-igniter-mix-task-info-global-options-0-is-undefined-module-igniter-mix-task-info-is-not-available/65107/9

sevenseacat commented 3 months ago

Hm, it seemed possible because I've been mucking around with Igniter for a while, but mix archive only shows hex 2.1.1 and phx_new 1.7.14. Just replicated it on my other laptop :(

sevenseacat commented 3 months ago

So I searched all asdf-installed Elixir versions for any installed Igniter archives, and found two:

/Users/rebecca/.asdf/installs/elixir/1.15.7-otp-26
hex-2.1.1/         igniter_new-0.2.3/ phx_new-1.7.14/

/Users/rebecca/.asdf/installs/elixir/1.17.0-otp-27
hex-2.1.1/         igniter_new-0.2.3/

(note: I've been testing this with Elixir 1.17.2-otp-27)

Deleted the two archives and re-ran the test and it worked :( So not a bug in Igniter or AshPostgres, but what?

zachdaniel commented 3 months ago

This is definitely very strange, and I feel like there is some kind of pattern around this. I dont' see why the igniter_new archive would have anything to do with it. But two people who know what they are doing having this issue in quick succession indicates some kind of problem. Will keep an eye out.

sevenseacat commented 3 months ago

Just for funsies, I've gotten almost-identical problems again on $work_laptop when attempting to install both AshGraphql and AshJsonApi.

For AshGraphql, it prompts to add :ash_graphql to mix.exs, I confirm, it compiles everything, then the error occurs:

==> phoenix_ecto
Compiling 7 files (.ex)
Generated phoenix_ecto app
** (UndefinedFunctionError) function Igniter.Project.Formatter.import_dep/2 is undefined 
(module Igniter.Project.Formatter is not available)
    (igniter 0.3.9) Igniter.Project.Formatter.import_dep(%Igniter{rewrite: %Rewrite{sources: 
%{".formatter.exs" => %Rewrite.Source{from: :file, path: ".formatter.exs", content: "[\n  
import_deps: [:ash_postgres, :ash, :ecto, :ecto_sql, :phoenix],\n  subdirectories: [\"priv/*/
migrations\"],\n  plugins: [Spark.Formatter, Phoenix.LiveView.HTMLFormatter],\n  inputs: 
[\"*.{heex,ex,exs}\", \"{config,lib,test}/**/*.{heex,ex,exs}\", \"priv/*/seeds.exs\"]\n]\n", 
hash: <<76, 178, 39, 224, 31, 232, 124, 20, 141, 144, 125, 168, 78, 59, 186, 85>>, owner: 
Rewrite, filetype: %Rewrite.Source.Ex{quoted: {:__block__, [trailing_comments: [], 
leading_comments: [], end_of_expression: [newlines: 1, line: 6, column: 2], newlines: 1, 
closing: [line: 6, column: 1], line: 1, column: 1], [[{{:__block__, [trailing_comments: [], 
leading_comments: [], format: :keyword, line: 2, column: 3], [:import_deps]}, {:__block__, 
[trailing_comments: [], leading_comments: [], closing: [line: 2, column: 64],...
...
__, ...}}, {{:__block__, ...}, {...}}, {{...}, ...}, {...}, ...]]}}]]}]}}]]}, formatter: 
#Function<4.125904074/2 in Rewrite.Source.Ex.formatter/2>, opts: []}, history: [], issues: 
[], private: %{}}}, extensions: %{".ex" => Rewrite.Source.Ex, ".exs" => Rewrite.Source.Ex, 
"default" => Rewrite.Source}}, issues: [], tasks: [], warnings: [], assigns: %{igniter_exs: 
[]}, moves: %{}}, :ash_graphql)
    (ash_graphql 1.2.1) lib/mix/tasks/ash_graphql.install.ex:10: Mix.Tasks.AshGraphql.Install.igniter/2
    (elixir 1.17.2) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
    (igniter 0.3.9) lib/igniter/util/install.ex:101: Igniter.Util.Install.run_installers/5
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.2) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /Users/rebecca/.asdf/installs/elixir/1.17.2-otp-27/bin/mix:2: (file)

Same thing with AshJsonApi, but a different error:

==> phoenix_ecto
Compiling 7 files (.ex)
** (UndefinedFunctionError) function Igniter.Libs.Phoenix.web_module_name/1 is undefined 
(module Igniter.Libs.Phoenix is not available)
    (igniter 0.3.9) Igniter.Libs.Phoenix.web_module_name("AshJsonApiRouter")
    (ash_json_api 1.3.8) lib/mix/tasks/ash_json_api.install.ex:14: Mix.Tasks.AshJsonApi.Install.igniter/2
    (elixir 1.17.2) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
    (igniter 0.3.9) lib/igniter/util/install.ex:101: Igniter.Util.Install.run_installers/5
    (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.2) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /Users/rebecca/.asdf/installs/elixir/1.17.2-otp-27/bin/mix:2: (file)

This machine has no installed Igniter archives. I have a whole lot of Elixir versions installed, all have hex-2.x.x, some have phx_new-1.7.x, but no Igniter at all.

Re-running the installs works fine for both of them. It doesn't compile anything (I guess compilation finished the first time I ran it?), just jumps straight to the results of running the package installer.

I tried deleting ~/.hex/cache.ets and reran the setup after deleting deps/ash_(package) and _build/dev/lib/ash_(package), and it still failed.

Something weird is going on.