question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Be sure to mark the schema as nullable" message shouldn't be always shown

See original GitHub issue

Hey, first time opening issue here, so let me just preface that I love this package. It really hits all the sweet spots and scope of features that I need 😍. Thank you for creating it!


As for the issue:

What happens?

It seems that when the input is null then there is this ValidationError returned:

... must be a `string` type, but the final value was: `null`.
If "null" is intended as an empty value be sure to mark the schema as `.nullable()`

Problem

First line seems proper and something that is expected.

But the second line seems too verbose and something that should be only returned optionally in the development environment. Currently it’s returned always - without any way to easily disable it

I also think it should not be returned as a ValidationError message, but rather logged as a console warning or something similar.

The line in the source: https://github.com/jquense/yup/blob/master/src/locale.js#L18

Context

In certain cases, I’m returning ValidationError messages to the end user of my application. And my end users should only see the reasons of why their input failed. They shouldn’t see messages intended for a developer.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
ArcOmotolacommented, Aug 10, 2022

Try adding .nullable() to the chain of validations.

validationSchema={object().shape({ category: string().required(“Category is required.”).nullable() })}

Hope this helps.

4reactions
DominikSerafincommented, Aug 27, 2019

@jquense indeed makes sense

This is however problematic when your application is something like an API service where the end users are actually technical folks and they can e.g. submit JSON that can contain different type of values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Formik & yup form validation not working as expected with ...
Try adding .nullable() to the chain of validations. validationSchema={object().shape({ category: string().required("Category is required.
Read more >
Resolve nullable warnings | Microsoft Learn
Several compiler warnings indicate code that isn't null-safe. Learn how to address those warnings by making your code more resilient.
Read more >
Java static code analysis: "@NonNull" values should not be ...
Fields, parameters and return values marked @NotNull , @NonNull , or @Nonnull are assumed to have non-null values and are not typically null-checked...
Read more >
Using nullability in GraphQL
A field can either be nullable or non-null, and this tells you whether or not you could receive a null value when you...
Read more >
Why you Should Always Specify Whether a Column Accepts ...
You might think that if you don't include the NOT NULL constraint in the column's definition, then the column will be nullable. No,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found