Skip to content
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 error messages for validation failures #6218

Merged
merged 2 commits into from
Aug 1, 2021

Conversation

timleslie
Copy link
Contributor

@timleslie timleslie commented Jul 29, 2021

This PR updates the error message provided during the validation phase of our CRUD mutations. The changes are:

  • Changed the top level message to something a bit more specific
  • Include the individual error messages in a list below the top level message
  • Include the list/field name in the individual error messages for context.
  • All phases of validation (isRequired, field hooks, list hooks) are now run to completion before returning the errors, so as to provide as much feedback as possible to the user.

Config

...
      label: text({
        isRequired: true,
        hooks: {
          validateInput: ({ resolvedData, addValidationError }) => {
            if (resolvedData.label === 'bad') {
              addValidationError(`"${resolvedData.label}" is not allowed.`);
            }
          },
        },
      }),
      priority: select({
        dataType: 'enum',
        options: [
          { label: 'Low', value: 'low' },
          { label: 'Medium', value: 'medium' },
          { label: 'High', value: 'high' },
        ],
        isRequired: true,
      }),
...

Before

Screen Shot 2021-07-30 at 9 10 06 am

After

Screen Shot 2021-07-30 at 9 06 18 am

@vercel
Copy link

vercel bot commented Jul 29, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/Fh8CAkfimkvhEjDCQjkeeJwKkLU3
✅ Preview: https://keystone-next-docs-git-update-validation-messages-keystonejs.vercel.app

@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2021

🦋 Changeset detected

Latest commit: cc90f8a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@keystone-next/example-testing Patch
@keystone-next/keystone Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel vercel bot temporarily deployed to Preview July 29, 2021 04:56 Inactive
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 29, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@timleslie timleslie force-pushed the update-validation-messages branch from a89ea23 to 02900c3 Compare July 29, 2021 05:29
@vercel vercel bot temporarily deployed to Preview July 29, 2021 05:29 Inactive
@vercel vercel bot temporarily deployed to Preview July 29, 2021 05:34 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from 29c3d3c to 0ae205c Compare July 29, 2021 06:06
@vercel vercel bot temporarily deployed to Preview July 29, 2021 06:07 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from 0ae205c to b5d2702 Compare July 29, 2021 06:36
@vercel vercel bot temporarily deployed to Preview July 29, 2021 06:36 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from b5d2702 to 3e7b008 Compare July 29, 2021 23:00
@vercel vercel bot temporarily deployed to Preview July 29, 2021 23:00 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from 3e7b008 to 4bf7a5b Compare July 29, 2021 23:15
@vercel vercel bot temporarily deployed to Preview July 29, 2021 23:15 Inactive
@vercel vercel bot temporarily deployed to Preview July 29, 2021 23:55 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from 7735ad2 to 0398125 Compare July 30, 2021 00:25
@vercel vercel bot temporarily deployed to Preview July 30, 2021 00:25 Inactive
@timleslie timleslie changed the title [WIP] Improve error messages for validation failures Improve error messages for validation failures Jul 30, 2021
@timleslie timleslie requested a review from JedWatson July 30, 2021 00:31
@timleslie timleslie enabled auto-merge (squash) July 30, 2021 00:35
@timleslie timleslie force-pushed the update-validation-messages branch from 0398125 to 4ba0286 Compare July 30, 2021 00:35
@vercel vercel bot temporarily deployed to Preview July 30, 2021 00:35 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from 4ba0286 to ca0c68e Compare July 30, 2021 04:47
@vercel vercel bot temporarily deployed to Preview July 30, 2021 04:47 Inactive
@timleslie timleslie force-pushed the update-validation-messages branch from ca0c68e to c979cd8 Compare July 30, 2021 05:45
@vercel vercel bot temporarily deployed to Preview July 30, 2021 05:45 Inactive
@vercel vercel bot temporarily deployed to Preview August 1, 2021 23:09 Inactive
@timleslie timleslie merged commit c7e331d into master Aug 1, 2021
@timleslie timleslie deleted the update-validation-messages branch August 1, 2021 23:15
Nikitoring pushed a commit to Nikitoring/keystone that referenced this pull request Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants