unjs / h3

⚡️ Minimal H(TTP) framework built for high performance and portability

Home Page:https://h3.unjs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use `myzod`

Barbapapazes opened this issue · comments

Describe the change

Hello,

In the documentation, there is a page about data validation that says it's possible to use myzod. However, parsing params (and body) does not works because of this error:

Cannot read properties of undefined (reading 'Symbol(shapeKeys)')

The reproduction: https://github.com/barbapapazes/myzod-h3

You can start the open with node server.mjs and open you browser localhost:3000 and check the terminal where you launch node. You will see this error, similar to above:

H3Error: Cannot read properties of undefined (reading 'Symbol(shapeKeys)')
    at createError (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:79:15)
    at createValidationError (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:245:9)
    at validateData (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:241:11)
    at getValidatedRouterParams (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:272:10)
    at Object.handler (file:///home/esteban/dev/r/myzod-h3/src/app.mjs:21:28)
    at Object.handler (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2196:34)
    at Object.handler (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:31)
    at Server.toNodeHandle (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:17)
    at Server.emit (node:events:518:28)
    at parserOnIncoming (node:_http_server:1137:12) {
  cause: {
    status: 400,
    statusMessage: 'Validation Error',
    message: "Cannot read properties of undefined (reading 'Symbol(shapeKeys)')",
    data: TypeError: Cannot read properties of undefined (reading 'Symbol(shapeKeys)')
        at parse (/home/esteban/dev/r/myzod-h3/node_modules/.pnpm/myzod@1.11.0/node_modules/myzod/libs/types.js:548:26)
        at validateData (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:232:23)
        at getValidatedRouterParams (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:272:10)
        at Object.handler (file:///home/esteban/dev/r/myzod-h3/src/app.mjs:21:28)
        at Object.handler (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2196:34)
        at Object.handler (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:31)
        at Server.toNodeHandle (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:17)
        at Server.emit (node:events:518:28)
        at parserOnIncoming (node:_http_server:1137:12)
        at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
  },
  statusCode: 400,
  fatal: false,
  unhandled: false,
  statusMessage: 'Validation Error',
  data: TypeError: Cannot read properties of undefined (reading 'Symbol(shapeKeys)')
      at parse (/home/esteban/dev/r/myzod-h3/node_modules/.pnpm/myzod@1.11.0/node_modules/myzod/libs/types.js:548:26)
      at validateData (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:232:23)
      at getValidatedRouterParams (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:272:10)
      at Object.handler (file:///home/esteban/dev/r/myzod-h3/src/app.mjs:21:28)
      at Object.handler (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2196:34)
      at Object.handler (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:31)
      at Server.toNodeHandle (file:///home/esteban/dev/r/myzod-h3/node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:17)
      at Server.emit (node:events:518:28)
      at parserOnIncoming (node:_http_server:1137:12)
      at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
}

URLs

https://h3.unjs.io/examples/validate-data#utilities-for-validation

Additional information

  • Would you be willing to help?

Works as expected if you pass data as explicit argument

Works

const params = await getValidatedRouterParams(event, (data) => validator.parse(data))

Breaks

const params = await getValidatedRouterParams(event, validator.parse)

Barbapapazes/myzod-h3#2

Works as expected if you pass data as explicit argument

Works

const params = await getValidatedRouterParams(event, (data) => validator.parse(data))

Breaks

const params = await getValidatedRouterParams(event, validator.parse)

Barbapapazes/myzod-h3#2

Interesting 🤔

Do you know why? And we could update the docs to be more explicite about that case.