ash-project / ash-project/ash

Auto-detect whether fields from validation errors are attributes or arguments

Open
#2,360 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
2.5k
Forks
426
Avg merge
23h 26m
Merged PRs (30d)
46

Description

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

### AI Policy

- [x] I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

### Is your feature request related to a problem? Please describe.

When writing a custom validation, if I return

```elixir
{:error, field: :my_argument, message: "message"}
```

from the `validate` callback, it generates an `Ash.Error.Changes.InvalidAttribute` error, even if the specified field is an argument.

### Describe the solution you'd like

It seems to me like it would make sense to automatically detect whether it's an attribute or argument and return the associated exception type.

### Describe alternatives you've considered

This isn't a huge deal because I can call `Ash.Error.Changes.InvalidArgument.exception` directly and return that from the validate callback, but it's a bit more verbose IMO

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by tracing how the validate callback handles returned {:error, field: ..., message: ...} values and compare the InvalidAttribute and InvalidArgument exception paths. Done means the field is detected as an attribute or argument and the associated exception type is returned automatically, while the existing direct InvalidArgument.exception alternative remains unnecessary.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.