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

Error handling on websocket stream error message #706

Closed
Luiz-Monad opened this issue Apr 22, 2024 · 0 comments
Closed

Error handling on websocket stream error message #706

Luiz-Monad opened this issue Apr 22, 2024 · 0 comments

Comments

@Luiz-Monad
Copy link
Contributor

Luiz-Monad commented Apr 22, 2024

Why am I getting an undefined error when I receive a stream:error IQ message ?

This is the relevant line:

const e = error.children[i];

And it only happens when the connection is already open, not when connecting as evidenced by onMessage processing on my call stack.

const data = this._streamWrap(message.data);

It seems someone had changed it from

for (let i = 0; i < error.childNodes.length; i++) {
            const e = error.childNodes[i];

to

       for (let i = 0; i < error.childNodes.length; i++) {
            const e = error.children[i];

as part of some refactoring. (children is not valid as per xmldom/xmldom#410)

I am using the ejabberd server and it was sending a "spurious" stream:error because of a misconfiguration, but I need to be able to catch the error instead of it going as unhandled exception to the nodejs handler.

[edit: added the complete callstack]

[1] [16:23:32.982] ERROR (server): UNHANDLED 
[1]     err: {
[1]       "type": "TypeError",
[1]       "message": "Cannot read properties of undefined (reading '0')",
[1]       "stack":
[1]           TypeError: Cannot read properties of undefined (reading '0')
[1]               at Websocket._checkStreamError (\lib\server.js:5627:37)
[1]               at Websocket._onMessage (\lib\server.js:6015:18)
[1]               at socket.onmessage (\lib\server.js:5810:45)
[1]               at callListener (\node_modules\ws\lib\event-target.js:290:14)
[1]               at WebSocket.onMessage (\node_modules\ws\lib\event-target.js:209:9)
[1]               at WebSocket.emit (node:events:519:28)
[1]               at WebSocket.emit (node:domain:488:12)
[1]               at Receiver.receiverOnMessage (\node_modules\ws\lib\websocket.js:1209:20)
[1]               at Receiver.emit (node:events:519:28)
[1]               at Receiver.emit (node:domain:488:12)
[1]     }
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

2 participants