Comments (4)
I agree that the current behavior is not good.
It's the "expected behavior" given how the messaging system currently works, not in the sense that it's correct overall and especially not in your case: as I wrote above, the current behavior would work fine for refinements of scalar values (such as string
or number
) but not for refinements of more complex data structures like the case you presented (a refinement of an array of structs).
So the behavior encoded in the formatter needs to be refactored to improve it, which is exactly what I'm doing right now by working on the development branch of the next minor #2634
from effect.
The behavior is as intended, meaning that when setting a custom message, it takes precedence over everything else (see https://github.com/Effect-TS/effect/blob/main/packages/schema/README.md#custom-error-messages). However, upon reflection, I realize that this logic may work well for scalar value refinements but not for a case like this, where we refine a more complex data structure (such as an array of a struct). Therefore, I'm considering refactoring the message logic in the next minor version of the schema so that the high precedence of the message is opt-in.
In short, the logic could be as follows, given a filter:
- If there is a custom message defined on it:
- If this message is marked as
override: true
, then this message is used unless the error concerns a previous refinement and that refinement has a custom message, in which case the message of that previous refinement is calculated. - If the message is NOT marked with
override: true
:- If the error concerns this refinement and not a previous one, its custom message is used.
- Otherwise, if the error concerns a previous refinement, the corresponding message is calculated.
- If this message is marked as
- Otherwise, the default message is calculated.
from effect.
Just to give more details on my usage as this might be a common use-case.
I have a form which contains a list of items. This list needs to have at least one item. Each item needs to be a string with length > 1 and < 50.
I want to be able to show an error next to the input that is currently invalid.
It would be awkward for the user to start writing their 3rd item in the list, somehow make that item invalid and have an error saying that the list does not have at least 1 item.
I really can't understand how the expected behaviour could be to show a minLength error on an array that has 3 items.
from effect.
Awesome, thank you for the quick feedback.
from effect.
Related Issues (20)
- From Discord: Schema template literal issue after upgrading to @effect/[email protected]
- JSR computability HOT 1
- From Discord: Setting response cookies from RPC calls HOT 2
- From Discord: Clarification on `onExcessProperty: preserve` Behavior: Key Order Not Maintained
- `Cause` pretty printing is broken for multi-line error messages
- Strict pattern matching HOT 7
- From Discord: Request for `Chunk.lastNonEmpty` Method in Code Library
- From Discord: Ensure `Chunk.reverse` Preserves NonEmpty Status in Output
- `Struct.evolve` no compile time error for non function transformers HOT 2
- From Discord: Request to Add `Schema.NonEmptyChunk` HOT 1
- From Discord: Assigning Error Messages to Specific Inputs in Effect/Schema with Hook Resolvers HOT 1
- More precise `dual` signature (prevent type errors/issues) HOT 15
- From Discord: Detecting ParseError in `decode*Sync` for Error Retry Handling in `@tanstack/react-query`
- From Discord: (bug?) TypeError when using discard option with Effect.all HOT 1
- Implement `at` method for tuples
- Cli: --log-level flag HOT 3
- Requires DOM lib HOT 2
- Standard type extraction HOT 5
- From Discord: Pattern matching with typeguard - different array sizes
- Add "recursive" option to `FileSystem.watch`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from effect.