Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jamescarr opened this issue Oct 23, 2024 · 0 comments
Open

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

jamescarr opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jamescarr
Copy link

jamescarr commented Oct 23, 2024

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

  • Elixir version 1.17.2
  • Erlang version Erlang/OTP 26 [erts-14.2.5]
  • OS Sonoma 14.5
  • Ash version 3.4.35
@jamescarr jamescarr added bug Something isn't working needs review labels Oct 23, 2024
@zachdaniel zachdaniel added good first issue Good for newcomers and removed needs review labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Someday
Development

No branches or pull requests

2 participants