Skip to content

[Bug]: Errors do not result in an error event #1939

@SystemParadox

Description

@SystemParadox

MQTTjs Version

5.8.0

Broker

other

Environment

NodeJS

Description

For many kinds of error all you get is a close event - the error event is not emitted so you have no idea what the problem is.

Adding DEBUG=mqttjs:* shows the following:

mqttjs:client _writePacket :: emitting `packetsend`
mqttjs:client _writePacket :: writing to stream
mqttjs:client _writePacket :: writeToStream result false
mqttjs:client streamErrorHandler :: error Username is required to use password
mqttjs:client noop :: Error: Username is required to use password

I should not have to enable DEBUG to see this, the error event should have been emitted to inform the rest of my application.

I checked the source and for some reason this.stream.on('error') seems to noop anything without an err.code which seems very wrong to me.

Minimal Reproduction

One simple way to reproduce is to try connecting with a password but no username, but it seems to suppress almost everything.

Debug logs

mqttjs:client _writePacket :: emitting `packetsend`
mqttjs:client _writePacket :: writing to stream
mqttjs:client _writePacket :: writeToStream result false
mqttjs:client streamErrorHandler :: error Username is required to use password
mqttjs:client noop :: Error: Username is required to use password

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions