-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Superstruct error messages for invalid UI #2692
Comments
FrederikBolding
added a commit
that referenced
this issue
Sep 3, 2024
Add support for nested unions in `typedUnion`. The structs will be flattened before validation occurs. Progresses #2692 --------- Co-authored-by: MetaMask Bot <[email protected]>
Mrtenz
added a commit
that referenced
this issue
Sep 10, 2024
…2696) Adds `selectiveUnion` and rewrites a bunch of structs to use this pattern. This helps alleviate a problem where Superstruct errors would be impossible to read. The idea of `selectiveUnion` is to be able to guide Superstruct validation more with simple checks that can be used to choose between validation paths. This combined with `typedUnion` makes it possible to have drastically improved error messages for structs that use unions. This PR rewrites some of the UI structs to use these new patterns, but is not necessarily exhaustive. It also adds support for refinements and coercion to `typedUnion`. Generally, this PR turns errors like this: ``` Invalid params: At path: ui -- Expected the value to satisfy a union of `union | union`, but received: "foo".' ``` into errors like this: ``` Invalid params: At path: ui -- Expected type to be one of: "Address", "Bold", "Box", "Button", "Copyable", "Divider", "Dropdown", "RadioGroup", "FileInput", "Form", "Heading", "Input", "Image", "Italic", "Link", "Row", "Spinner", "Text", "Tooltip", "Checkbox", "Card", "Icon", "Selector", "Section", "Container", but received: undefined. ``` This PR does not solve this problem for structs that use the `children()` utility function with more than one struct as the input (e.g. `Button`). These components will fail with something like: ``` Invalid params: At path: ui.props.children.1.props.children.props.children -- Expected the value to satisfy a union of `union | object | object`, but received: [object Object]. ``` There may also still be other UI components that fail with similar errors, however, this is a huge step forward in readability and therefore dev-ex. Progresses #2692 --------- Co-authored-by: Maarten Zuidhoorn <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error message for any part of your UI being invalid is currently:
This happens because we are wrongly selecting the error message based on the Superstruct failures. For developer experience purposes we will need to rectify this
The text was updated successfully, but these errors were encountered: