You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Elysia,t}from'elysia'process.env.NODE_ENV='production'constapp=newElysia().onError(({ error, code })=>{console.log(error)return{ code }}).post('/',({ body })=>body,{body: t.Object({name: t.String()})}).listen(3000)console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`)
with the following request to trigger a validation error:
curl -X POST http://localhost:3000 -H 'content-type: application/json' -d '{"name": 1}'
What is the expected behavior?
Response should be:
{"code":"VALIDATION"}
What do you see instead?
Response is:
{"code":"UNKNOWN"}
and the following is logged:
191 | : 'Errors' in validator
192 | ? validator.Errors(value).First()
193 | : Value.Errors(validator, value).First()
194 |
195 | const customError =
196 | error.schema.message || error?.schema.error !== undefined
^
TypeError: undefined is not an object (evaluating 'error2.schema')
Additional information
Since Elysia version 1.2.3 the possibly undefined error is accessed without optional chain in the class ValidationError.
What version of Elysia is running?
1.2.10
What platform is your computer?
Darwin 24.2.0 arm64 arm
What steps can reproduce the bug?
For the following Bun application:
with the following request to trigger a validation error:
What is the expected behavior?
Response should be:
What do you see instead?
Response is:
and the following is logged:
Additional information
Since Elysia version 1.2.3 the possibly
undefined
error is accessed without optional chain in the classValidationError
.From
src/error.ts
:The
error
object should be accessed safely as it can beundefined
in production environment (NODE_ENV
orENV
isproduction
).Have you try removing the
node_modules
andbun.lockb
and try again yet?Yes
The text was updated successfully, but these errors were encountered: