Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 -> v5 migration. Is the change of reply payload check somewhere documented? #1072

Open
globalexport opened this issue Dec 3, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@globalexport
Copy link

💬 Change introduced in v5.0.0-alpha.4 is crashing my application

In fastify/lib/reply.js this part was removed:

  // Response
  if (isResponse) {
    // https://developer.mozilla.org/en-US/docs/Web/API/Response/headers
    if (typeof payload.headers === 'object' && typeof payload.headers.forEach === 'function') {
      for (const [headerName, headerValue] of payload.headers) {
        reply.header(headerName, headerValue)
      }
    }

    // https://developer.mozilla.org/en-US/docs/Web/API/Response/body
    if (payload.body != null) {
      if (payload.bodyUsed) {
        throw new FST_ERR_REP_RESPONSE_BODY_CONSUMED()
      }
      // Response.body always a ReadableStream
      sendWebStream(payload.body, res, reply)
    }
    return
  }

Instead of the above, the process is running into

  if (typeof payload !== 'string' && !Buffer.isBuffer(payload)) {
    throw new FST_ERR_REP_INVALID_PAYLOAD_TYPE(typeof payload)
  }

I failed to find documentation regarding this breaking change in the migration documentations. Maybe I am missing something?
https://fastify.dev/docs/v5.0.x/Guides/Migration-Guide-V5/
https://fastify.dev/docs/v5.1.x/Guides/Migration-Guide-V5/

/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:642
    throw new FST_ERR_REP_INVALID_PAYLOAD_TYPE(typeof payload)
          ^
FastifyError [Error]: Attempted to send payload of invalid type 'object'. Expected a string or Buffer.
    at onSendEnd (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:642:11)
    at wrapOnSendEnd (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:536:5)
    at next (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/hooks.js:289:7)
    at handleResolve (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/hooks.js:306:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'FST_ERR_REP_INVALID_PAYLOAD_TYPE',
  statusCode: 500
}
Node.js v20.16.0
[nodemon] app crashed - waiting for file changes before starting...

Environment

  • node version: 20
  • fastify version: >=v5.0.0-alpha.4
  • os: Mac, Linux
@globalexport globalexport added the help wanted Extra attention is needed label Dec 3, 2024
@metcoder95
Copy link
Member

Noup, it stills here: https://github.com/fastify/fastify/blob/8f3eab6dd7d3524a684f83f5c49d5795f2babe83/lib/reply.js#L573-L594

Can you try with latest version?

@globalexport
Copy link
Author

Hi @metcoder95 !

Thank you for your help.

The stacktrace above was created with the latest version v5.1.0 (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:642)

@jsumners
Copy link
Member

jsumners commented Dec 5, 2024

Please provide a minimal reproducible example, written in JavaScript. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).

@globalexport
Copy link
Author

Hi @jsumners !

Thank you. I will need some time to compile a reproducible setup. The error is occuring during a rather complex single-sign-on process which is involving different dependencies (e.g., grant, @fastify/http-proxy).
Hope to get it done before Christmas, but can't say for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants