Skip to content

Commit 2830995

Browse files
committed
Fail promise when message.serialize throws an error
1 parent 65cef27 commit 2830995

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/MQTTNIO/MQTTChannelHandlers.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ final class MQTTEncodeHandler: ChannelOutboundHandler {
1616
let message = unwrapOutboundIn(data)
1717
logger.debug("MQTT Out", metadata: ["mqtt_message": .string("\(message)")])
1818
var bb = context.channel.allocator.buffer(capacity: 0)
19-
try! message.serialize(to: &bb)
20-
context.write(wrapOutboundOut(bb), promise: promise)
19+
do {
20+
try message.serialize(to: &bb)
21+
context.write(wrapOutboundOut(bb), promise: promise)
22+
} catch {
23+
promise?.fail(error)
24+
}
2125
}
2226
}
2327

0 commit comments

Comments
 (0)