ash-project / ash

A declarative, extensible framework for building Elixir applications.
https://www.ash-hq.org
MIT License
1.64k stars 220 forks source link

More Descriptive Error Messages for `ash.gen.resource` #1553

Open jamescarr opened 1 month ago

jamescarr commented 1 month ago

Describe the bug Currently the error messages for incorrect attribute details when using ash.gen.resources can be a little confusing to end users.

To Reproduce Run the ash.gen.resource generator with any attribute options that don't exist.

mix ash.gen.resource AshDemo.Accounts.Profile \               
    --uuid-primary-key id \
    --attribute bio:text:optional:public \
    --relationship belongs_to:user:AshDemo.Accounts.User \
    --timestamps

It will output the following error message:

** (FunctionClauseError) no function clause matching in anonymous fn/1 in Mix.Tasks.Ash.Gen.Resource.attribute_modifier_string/1

    The following arguments were given to anonymous fn/1 in Mix.Tasks.Ash.Gen.Resource.attribute_modifier_string/1:

        # 1
        "optional"

    (ash 3.4.35) lib/mix/tasks/gen/ash.gen.resource.ex:303: anonymous fn/1 in Mix.Tasks.Ash.Gen.Resource.attribute_modifier_string/1
    (elixir 1.17.2) lib/enum.ex:1804: anonymous fn/2 in Enum.map_join/3
    (elixir 1.17.2) lib/enum.ex:4408: Enum.map_intersperse_list/3
    (elixir 1.17.2) lib/enum.ex:1804: Enum.map_join/3
    (ash 3.4.35) lib/mix/tasks/gen/ash.gen.resource.ex:290: anonymous fn/1 in Mix.Tasks.Ash.Gen.Resource.attributes/1
    (elixir 1.17.2) lib/enum.ex:1804: anonymous fn/2 in Enum.map_join/3
    (elixir 1.17.2) lib/enum.ex:4408: Enum.map_intersperse_list/3
    (elixir 1.17.2) lib/enum.ex:1804: Enum.map_join/3

Expected behavior Return an error response code but indicate the attribute modifier is unrecognizeable and perhaps point to the ones that are allowed.

Also, it will generate a resource with an incorrect type attribute (text in this case) which will compile error later and indicate the correct types. I think we should be able to check against that too.

Runtime