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

TypeError: Cannot convert undefined or null to object #883

Closed
stx opened this issue Jul 24, 2023 · 4 comments · Fixed by #888
Closed

TypeError: Cannot convert undefined or null to object #883

stx opened this issue Jul 24, 2023 · 4 comments · Fixed by #888

Comments

@stx
Copy link

stx commented Jul 24, 2023

We see this on production occasionally across different Node versions. Code wrongly assumes an object is always present.

TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at objectToArray (/usr/src/app/node_modules/readmeio/dist/src/lib/object-to-array.js:8:19)
    at processRequest (/usr/src/app/node_modules/readmeio/dist/src/lib/process-request.js:177:57)
    at constructPayload (/usr/src/app/node_modules/readmeio/dist/src/lib/construct-payload.js:67:67)
    at ServerResponse.startSend (/usr/src/app/node_modules/readmeio/dist/src/lib/log.js:141:64)
    at Object.onceWrapper (node:events:627:28)
    at ServerResponse.emit (node:events:525:35)
    at onFinish (node:_http_outgoing:950:10)
    at afterWrite (node:internal/streams/writable:499:5)
    at afterWriteTick (node:internal/streams/writable:486:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
@domharrington
Copy link
Member

Hey! Thanks for reporting... I think that error is coming from these lines:

return Object.entries(object).reduce((prev, [name, value]) => {

params: objectToArray(reqBody as Record<string, unknown>),

If I had to guess what's going on here, you have an HTTP request that looks like this:

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded

With a method of POST, a content-type of application/x-www-form-urlencoded but no request body? I think we're (incorrectly) assuming that all POST requests will have bodies. We're then calling Object.entries(undefined) which throws the error you're getting above! Does that sound about right?

@stx
Copy link
Author

stx commented Jul 25, 2023 via email

domharrington added a commit that referenced this issue Jul 26, 2023
We were wrongly assuming that POST bodies will always be set for
`application/x-www-form-urlencoded` requests. This fixes that!

Fixes #883
@domharrington
Copy link
Member

Fix for this over here, as soon as I get it reviewed then I'll release it! Thanks for your patience.

domharrington added a commit that referenced this issue Jul 26, 2023
We were wrongly assuming that POST bodies will always be set for
`application/x-www-form-urlencoded` requests. This fixes that!

Fixes #883
@domharrington
Copy link
Member

This fix has been published on npm at v6.2.0! Thanks again for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants