Auto-detect whether fields from validation errors are attributes or arguments
- 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
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