### Question:
MongoWireMessageEncoder extends MessageToByteEncoder<MongoMessage> { @Override protected void encode(ChannelHandlerContext ctx, MongoMessage message, ByteBuf buf) { buf.writeIntLE(0); buf.writeIntLE(message.getHeader().getRequestID()); buf.writeIntLE(message.getHeader().getResponseTo()); buf.writeIntLE(OpCode.OP_MSG.getId()); buf.writeIntLE(message.getFlags()); buf.writeByte(MongoMessage.SECTION_KIND_BODY); Document document = message.getDocument(); try { BsonEncoder.encodeDocument(document, buf); } catch (RuntimeException e) { log.error("Failed to encode {}", document, e); ctx.channel().close(); throw e; } log.debug("wrote message: {}", message); int writerIndex = buf.writerIndex(); buf.setIntLE(0, writerIndex); }    }### Answer:
@Test void testExceptionHandling() throws Exception { MongoWireMessageEncoder mongoWireEncoder = new MongoWireMessageEncoder(); MessageHeader header = new MessageHeader(0, 0); MongoMessage reply = new MongoMessage(channel, header, new Document("key", Missing.getInstance())); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> mongoWireEncoder.encode(ctx, reply, Unpooled.buffer())) .withMessageContaining("Unexpected missing value. This must not happen. Please report a bug."); verify(channel).close(); }