elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.23k stars 198 forks source link

Validation error message unclear when requiring array length #598

Closed m1212e closed 3 months ago

m1212e commented 3 months ago

I use a schema with a required min length for an input schema:

t.Array( ..., { minItems: 1 },)

But when I provide an empty array I get an error like this:

Error in POST /my/path: VALIDATION {"type":"validation","on":"body","found":{"user":{"authProviderId":"dfaeabff"},"resources":[]}}. Thrown at Error: {"type":"validation","on":"body","found":{"user":{"authProviderId":"dfaeabff"},"resources":[]}}
    at new _ValidationError (/app/prod/node_modules/elysia/dist/index.mjs:2379:9)
    at <anonymous> (:110:49)
    at processTicksAndRejections (:12:39)

There is no hint on why the request failed/why the validation failed. Something like: "The array does not match the required length" would be nice. Is this an elysia thing or should I ask @sinclairzx81 over at the typebox repo?

kidqueb commented 3 months ago

Can you expand on your specific use? I was returned useful errors when the body was an object with an array in it or just an array itself.

Screenshot 2024-04-08 at 5 08 00 PM Screenshot 2024-04-08 at 5 08 37 PM