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

Bot exits with TypeError: Cannot use 'in' operator to search for 'errcode' #213

Closed
stronk7 opened this issue May 12, 2022 · 3 comments
Closed

Comments

@stronk7
Copy link

stronk7 commented May 12, 2022

We recently have deployed a bot using this and we have detected that sometimes it exits (2 times in 72h) with the following error in the logs:

/srv/node_modules/matrix-bot-sdk/lib/http.js:89
            if (errBody \u0026\u0026 'errcode' in errBody) {
                                     ^

TypeError: Cannot use 'in' operator to search for 'errcode' in Bad Gateway
    at Request._callback (/srv/node_modules/matrix-bot-sdk/lib/http.js:89:38)
    at Request.self.callback (/srv/node_modules/request/request.js:185:22)
    at Request.emit (node:events:527:28)

/srv/node_modules/matrix-bot-sdk/lib/http.js:89
            if (errBody \u0026\u0026 'errcode' in errBody) {
    at Request.\u003canonymous\u003e (/srv/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:527:28)

TypeError: Cannot use 'in' operator to search for 'errcode' in Bad Gateway
    at IncomingMessage.\u003canonymous\u003e (/srv/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:641:28)
    at Request._callback (/srv/node_modules/matrix-bot-sdk/lib/http.js:89:38)
    at IncomingMessage.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at Request.self.callback (/srv/node_modules/request/request.js:185:22)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
    at Request.emit (node:events:527:28)
    at Request.\u003canonymous\u003e (/srv/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:527:28)
    at IncomingMessage.\u003canonymous\u003e (/srv/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:641:28)
    at IncomingMessage.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Haven't been able to detect any message in particular causing that, and the whole stack trace seems to be "internal" to the sdk, so cannot provide much more information. If there is anything else we can provide, let me know.

Ciao :-)

@jaller94
Copy link
Contributor

Yep, here is the same error with a different output. This one highlights that the http lib tries to parse a JSON attribute "errcode" even if the webserver didn't return (valid) JSON.

As with the previous comment, this happened when the homeserver was busy and a reverse proxy answered "Bad Gateway".

/home/jaller94/Experiments/position/node_modules/matrix-bot-sdk/lib/http.js:89
            if (errBody && 'errcode' in errBody) {
                                     ^
TypeError: Cannot use 'in' operator to search for 'errcode' in <html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

    at Request._callback (/home/jaller94/Experiments/position/node_modules/matrix-bot-sdk/lib/http.js:89:38)
    at Request.self.callback (/home/jaller94/Experiments/position/node_modules/request/request.js:185:22)
    at Request.emit (node:events:527:28)
    at Request.emit (node:domain:475:12)
    at Request.<anonymous> (/home/jaller94/Experiments/position/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:527:28)
    at Request.emit (node:domain:475:12)
    at IncomingMessage.<anonymous> (/home/jaller94/Experiments/position/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:641:28)
    at IncomingMessage.emit (node:events:539:35)

@Half-Shot
Copy link
Contributor

This is fixed by #211

@turt2live
Copy link
Owner

#211 landed

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

No branches or pull requests

4 participants