Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Validation errors reported by zod are not useful #64

Open
Fleny113 opened this issue Dec 16, 2021 · 10 comments
Open

Validation errors reported by zod are not useful #64

Fleny113 opened this issue Dec 16, 2021 · 10 comments

Comments

@Fleny113
Copy link

Fleny113 commented Dec 16, 2021

Issue description

Calling toJSON() from an instance of a SlashCommandBuilder without setting required parameters (name and description) throw an error that seem from zod that isn't useful at all to understand the problem because of the size of the error and don't say what parameter is missing.

Original message:
When creating a SlashCommandBuilder and doing toJSON() zod thrown about an recived undefined and expect a string.

Step to reproduce:

  1. Import SlashCommandBuilder from @discordjs/builders
  2. Create a new Builder and call toJSON()
  3. zod should throw an error that isn't useful at all

zodError.log

Code sample

import { SlashCommandBuilder } from "@discordjs/builders";
new SlashCommandBuilder().setName("test").toJSON();

@discordjs/builders version

0.9.0

Node.js version

node.js v17.2.0 | Typescript 4.5.4

Operating system

Windows 11

Priority this issue should have

High (immediate attention needed)

@Fleny113 Fleny113 added bug Something isn't working need repro labels Dec 16, 2021
@vladfrangu
Copy link
Member

Is your code..minified/bundled at all? Because it definitely throws an error, as seen at the end, but a really, REALLY not helpful one

@Khasms
Copy link
Contributor

Khasms commented Dec 16, 2021

The issue is you didn't provide a description but the description is required.

@Fleny113
Copy link
Author

Is your code..minified/bundled at all? Because it definitely throws an error, as seen at the end, but a really, REALLY not helpful one

No, i having this issue from typescript (and tsc) but i tried directly from nodejs and still throw error

The issue is you didn't provide a description but the description is required.

Sorry, i added it.

@vladfrangu
Copy link
Member

That's not what @Khasms meant haha. You need to call .setDescription on the builder you created! For further questions, feel free to ask in our Discord server

@Fleny113
Copy link
Author

That's not what @Khasms meant haha. You need to call .setDescription on the builder you created! For further questions, feel free to ask in our Discord server

I known that is not he mean but really, i don't known what to write, the errore is useless.
Anyway, thanks for help.

@vladfrangu
Copy link
Member

Hrmm, true true, the errors could be better.. I'll be reopening this but with a different title 👍

@vladfrangu vladfrangu changed the title SlashCommandBuilder.toJSON() report error from zod Validation errors reported by zod are not useful Dec 17, 2021
@vladfrangu vladfrangu reopened this Dec 17, 2021
@Fleny113
Copy link
Author

Hrmm, true true, the errors could be better.. I'll be reopening this but with a different title 👍

I updated the description to made that more consistent with title

@hampuskraft
Copy link

hampuskraft commented Dec 17, 2021

Hi there, one possible alternative is to wrap parsing with a custom error that unsets the stacktrace, resulting in the below:

image

I'm willing to PR this if it seems like a good tradeoff. ValidationError can also be exported so it can be caught by consumers.

@Khasms
Copy link
Contributor

Khasms commented Dec 17, 2021

I can't reproduce the code dump at the beginning of the error, it outputs as it should on my end. But, as far as the error not being helpful, I opened #61 a week ago to improve them, so give some feedback on that if you see any other messages that need to be improved.

@kyranet
Copy link
Member

kyranet commented Dec 19, 2021

@hampuskraft Not a good tradeoff since that makes parsing +2x slower, which adds up to how slow Zod's validation already is, see discordjs/discord.js#7067 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants