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

Bug/FR: vague error when using vine.object() #17

Open
MoltenCoffee opened this issue Sep 15, 2023 · 3 comments
Open

Bug/FR: vague error when using vine.object() #17

MoltenCoffee opened this issue Sep 15, 2023 · 3 comments
Assignees
Labels
Type: Enhancement Improving an existing feature

Comments

@MoltenCoffee
Copy link

Package version

1.6.0

Describe the bug

This is submitted as a bug, but might as well be a documentation issue or feature request, depending how one looks at it.

My issue lies with vine.object, primarily the behaviour when one uses it as follows:

vine.object()
// instead of:
vine.object({})

This will generate the following error: TypeError: Cannot convert undefined or null to object, with a stacktrace that does not really help. The problem comes down to vine.object expecting an object as parameter. Developers using plain JS will have a hard time figuring this out, as the documentation isn't that clear on this either, note the word may:

Ensure the value of a field is a valid JavaScript object literal.
You __may__ define a collection of properties you want to validate within the object.

What should it do?

I believe there are several routes that could be picked, that are not mutually exclusive:

  • Implement a runtime check if an object is provided, and throw a clearer error if there is not
  • Give vine.object a default parameter ({})
  • Update the docs, stating that one must provide an object
  • Or even, allow vine.object() to work, just validating that something is an object (with/without allowUnknownProperties)

Reproduction repo

No response

@thetutlage
Copy link
Contributor

Is there any use case for creating an object without any properties?

@thetutlage thetutlage self-assigned this Nov 6, 2023
@MoltenCoffee
Copy link
Author

Oftentimes, there won't be. For me, the issue arose when I did not want to validate the contents of an object exported from a WYSIWYG editor (like tiptap or editorjs). I wanted vine to validate that an object was present, but skip checking the exact contents of it.

This is perfectly possible at the moment, but only with vine.object({}).allowUnknownProperties(). To me this feels cumbersome and inconsistent with the rest of the API. However, my main problem is the vagueness of the error.

@thetutlage thetutlage added the Type: Enhancement Improving an existing feature label Nov 15, 2023
@thetutlage
Copy link
Contributor

I see, that makes sense. Will improve the error message and allow an object without any arguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improving an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants