fastify / fastify/help

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

Open
#1,072 4 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

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

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

```js
// 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

```js
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/fastify@5.1.0/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/fastify@5.1.0/node_modules/fastify/lib/reply.js:642:11)
at wrapOnSendEnd (/path-to-project/node_modules/.pnpm/fastify@5.1.0/node_modules/fastify/lib/reply.js:536:5)
at next (/path-to-project/node_modules/.pnpm/fastify@5.1.0/node_modules/fastify/lib/hooks.js:289:7)
at handleResolve (/path-to-project/node_modules/.pnpm/fastify@5.1.0/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.