Skip to content

Commit e3e82d1

Browse files
authored
Include more details in the UnsupportedMessageTypeException when thrown (#296)
Motivation: Let's include some more details about why this exception was thrown and what we expected. Modifications: Use other constructor which will provide some useful informations Result: Easier to debug
1 parent 18fd091 commit e3e82d1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected void channelInputClosed(ChannelHandlerContext ctx) throws Exception {
134134
@Override
135135
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
136136
if (!(msg instanceof HttpObject)) {
137-
throw new UnsupportedMessageTypeException();
137+
throw new UnsupportedMessageTypeException(msg, HttpObject.class);
138138
}
139139
// 100-continue is typically a FullHttpResponse, but the decoded
140140
// Http3HeadersFrame should not handles as a end of stream.

src/test/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodecTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.netty.channel.socket.DuplexChannel;
3333
import io.netty.channel.socket.nio.NioDatagramChannel;
3434
import io.netty.handler.codec.EncoderException;
35+
import io.netty.handler.codec.UnsupportedMessageTypeException;
3536
import io.netty.handler.codec.http.DefaultFullHttpRequest;
3637
import io.netty.handler.codec.http.DefaultFullHttpResponse;
3738
import io.netty.handler.codec.http.DefaultHttpContent;
@@ -85,6 +86,7 @@
8586
import static org.hamcrest.Matchers.not;
8687
import static org.junit.jupiter.api.Assertions.assertEquals;
8788
import static org.junit.jupiter.api.Assertions.assertFalse;
89+
import static org.junit.jupiter.api.Assertions.assertNotNull;
8890
import static org.junit.jupiter.api.Assertions.assertThrows;
8991
import static org.junit.jupiter.api.Assertions.assertTrue;
9092

@@ -1069,4 +1071,13 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
10691071
group.shutdownGracefully();
10701072
}
10711073
}
1074+
1075+
@Test
1076+
public void testUnsupportedIncludeSomeDetails() {
1077+
EmbeddedQuicStreamChannel ch = new EmbeddedQuicStreamChannel(new Http3FrameToHttpObjectCodec(false));
1078+
UnsupportedMessageTypeException ex = assertThrows(
1079+
UnsupportedMessageTypeException.class, () -> ch.writeOutbound("unsupported"));
1080+
assertNotNull(ex.getMessage());
1081+
assertFalse(ch.finish());
1082+
}
10721083
}

0 commit comments

Comments
 (0)