You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user is working with effect/schema and react-hook-form to validate a form schema. They want to assign custom error messages to specific fields within a nested structure. The user is encountering an issue where the error message from a higher-level filter is being overridden by a message from a lower-level validation rule.
Key Points
Initial Schema Definition:
The user has a nested schema for an address, which includes fields like streetNumber, streetName, postalCode, etc.
They are using S.filter to validate the postalCode based on the country field.
Issue:
The error message from the filter on the postalCode field is being overridden by the message from the ValidString validation.
The user wants the custom error message from the filter to take precedence.
Possible Solutions:
One approach is to return a ParseIssue from the filter to indicate validation failure.
However, the message from ValidString still takes precedence.
Comparison with Zod:
In Zod, you can specify the path in the error message, which allows for more granular control.
Zod also has a global error mapping feature that can handle such cases more elegantly.
Current Implementation:
The user provided an example of how they are trying to implement the filter and custom error message in effect/schema.
The issue persists, and the user is considering moving the validation logic entirely into the filter.
Key Takeaways
Message Precedence:
The message from a lower-level validation (like minLength in ValidString) takes precedence over a higher-level filter's custom message.
Custom Error Handling:
Returning a ParseIssue from the filter can help in associating the error with a specific field, but it doesn't solve the precedence issue.
API Design:
Zod's approach to error handling, which includes specifying paths and global error mapping, provides more flexibility and control.
Need for Improvement:
The current API in effect/schema could be improved to allow more control over error message precedence, similar to Zod's approach.
Conclusion
The user is looking for a way to ensure that custom error messages from higher-level filters take precedence over lower-level validation messages. They are considering replicating Zod's API for better error handling and message control.
Summary
Summary
The user is working with
effect/schema
andreact-hook-form
to validate a form schema. They want to assign custom error messages to specific fields within a nested structure. The user is encountering an issue where the error message from a higher-level filter is being overridden by a message from a lower-level validation rule.Key Points
Initial Schema Definition:
streetNumber
,streetName
,postalCode
, etc.S.filter
to validate thepostalCode
based on thecountry
field.Issue:
filter
on thepostalCode
field is being overridden by the message from theValidString
validation.filter
to take precedence.Possible Solutions:
ParseIssue
from thefilter
to indicate validation failure.ValidString
still takes precedence.Comparison with Zod:
Current Implementation:
effect/schema
.filter
.Key Takeaways
Message Precedence:
minLength
inValidString
) takes precedence over a higher-level filter's custom message.Custom Error Handling:
ParseIssue
from the filter can help in associating the error with a specific field, but it doesn't solve the precedence issue.API Design:
Need for Improvement:
effect/schema
could be improved to allow more control over error message precedence, similar to Zod's approach.Conclusion
The user is looking for a way to ensure that custom error messages from higher-level filters take precedence over lower-level validation messages. They are considering replicating Zod's API for better error handling and message control.
Discord thread
https://discord.com/channels/795981131316985866/1249377412026732576
The text was updated successfully, but these errors were encountered: