Skip to content

Validation loose errors #1659

@Ivan-Baranov

Description

@Ivan-Baranov

What version of Elysia is running?

1.4.21

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What environment are you using

bun 1.3.5

Are you using dynamic mode?

for debug

What steps can reproduce the bug?

After update 1.4.16 -> 1.4.17+ response validation loose errors (return empty array in error.all and empty summary).

For debugging:

import { describe, expect, it } from 'bun:test'
import { Elysia, t } from 'elysia'

const app = new Elysia({
    aot: false,
})
    .post(
        '/test',
        () => {
            return {
                items: [
                    ['t1', { file: { ver: { s: '', m: null } } }],
                    ['t2', { file: { ver: null } }], // invalid response
                ],
            }
        },
        {
            body: t.Object({ }),
            response: t.Object({
                items: t.Array(t.Tuple([
                    t.String(),
                    t.Union([
                        t.Object({
                            file: t.Object({
                                ver: t.Object({
                                    s: t.String(),
                                    m: t.Nullable(t.String()),
                                }),
                            }),
                        }),
                    ]),
                ])),
            }),
        },
    )

describe('POST /test', () => {
    it('correct response', async () => {
        const req = new Request('http://localhost/test', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: '{}',
        })
        const res = await app.handle(req)
        const txt = await res.text()
        console.error(txt)
        expect(res.status).toBe(422)
    })
})

What is the expected behavior?

Test passed

What do you see instead?

Error 500
null is not an object (evaluating 'ar0p[1].file.ver.s')

Additional information

In real application response schema is huge, with aot = true - response 422, but error summary is empty.

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions