Overriding error messages
Nobody has claimed this yet.
- Dominant language
- Elixir
- Stars
- 92
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Hi. Enjoying the library so far.
I find that changing the error message of a schematic is quite cumbersome. It would be nice to have an easy to set the error message in a schematic. In some cases, the default error message is too long or too generic.
For example, oneof/1 with two schema schematics provides an error with the full signature of both modules.
I tried doing %Schematic{oneof([schematic1(), schematic2()]) | message: fn -> ... end}, but that is ignored because the unify function references the default message function.
Another example is that I had to do the following to get the messages to be consistent with the included schematics.
def decimal do
schematic =
raw(
fn
int when is_integer(int) ->
true
%Decimal{} ->
true
string when is_binary(string) ->
case Decimal.parse(string) do
{%Decimal{}, ""} -> true
_ -> false
end
_ ->
false
end,
message: "expected a decimal"
)
%{schematic | message: fn -> "a decimal" end}
end
all/1 is another that would benefit from being able to set a single error message regardless of which schematic fails.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how unify selects the message function, then inspect the oneof/1 and all/1 paths described in the issue. Determine how a schematic-level message override should interact with their default messages, and consider the decimal example as the expected customization outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100