Skip to content

ValidationError.all throws TypeError with Zod validators #1482

@ajaykarthikr

Description

@ajaykarthikr

What version of Elysia is running?

1.4.11

What platform is your computer?

Darwin 25.0.0 arm64 arm

What environment are you using

bun v1.3.0

Are you using dynamic mode?

No

What steps can reproduce the bug?

  1. Create an Elysia server with Zod schema validation
  2. Add an onError handler that tries to access error.all
  3. Make a request with invalid query parameters
import { Elysia, ValidationError } from "elysia";
import * as z from "zod";

const app = new Elysia()
  .onError(({ error, code }) => {
    if (error instanceof ValidationError) {
      // This line throws TypeError with Zod validators
      const errors = error.all;

      return {
        message: "Validation failed",
        errors: errors,
      };
    }
  })
  .get(
    "/test",
    ({ query }) => {
      return { success: true };
    },
    {
      query: z.object({
        name: z.string(),
        age: z.number(),
        filters: z.object({
          values: z.array(z.string()),
          mode: z.enum(["include", "exclude"]),
        }),
      }),
    }
  )
  .listen(3000);

console.log("Server running at http://localhost:3000");

### What is the expected behavior?

`error.all` should return an array of validation errors similar to TypeBox validators:

```typescript
[
  {
    summary: "Invalid input: expected number, received nan",
    path: "/age",
    value: "invalid",
  },
  {
    summary: "Invalid input: expected object, received string",
    path: "/filters",
    value: "",
  }
]

This should work consistently across all validators (TypeBox, Zod, Valibot, etc.) since Elysia 1.4 added Standard Schema support.

What do you see instead?

The following error is thrown:

431 |           Object.setPrototypeOf(this, ValidationError.prototype)
432 |   }
433 | 
434 |   get all() {
435 |           return 'Errors' in this.validator
436 |                   ? [...this.validator.Errors(this.value)].map(mapValueError)
                              ^
TypeError: Spread syntax requires ...iterable[Symbol.iterator] to be a function

Additional information

No response

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