From 626696dba89557e23c97ebe0a1d2ae03322c74df Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 19 Jul 2024 08:27:04 -1000 Subject: [PATCH] Correctly translate quiche error to QuicException that have no transport error mappings Motivation: There are a few errors that just dont have a transport error mapping, we need to special handle these Modifications: Correctly handle errors that have no mapping Result: Fixes https://github.com/netty/netty-incubator-codec-quic/issues/735 --- .../io/netty/incubator/codec/quic/QuicException.java | 12 ++++++++++-- .../java/io/netty/incubator/codec/quic/Quiche.java | 5 ++++- .../io/netty/incubator/codec/quic/QuicheError.java | 2 -- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicException.java b/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicException.java index 83a38b61..1d4cf018 100644 --- a/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicException.java +++ b/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicException.java @@ -15,6 +15,8 @@ */ package io.netty.incubator.codec.quic; +import org.jetbrains.annotations.Nullable; + /** * Exception produced while processing {@code QUIC}. */ @@ -22,6 +24,11 @@ public final class QuicException extends Exception { private final QuicTransportError error; + QuicException(String message) { + super(message); + this.error = null; + } + public QuicException(QuicTransportError error) { super(error.name()); this.error = error; @@ -42,12 +49,13 @@ public QuicException(String message, Throwable cause, QuicTransportError error) this.error = error; } - /** * Returns the {@link QuicTransportError} which was the cause of the {@link QuicException}. * - * @return the {@link QuicTransportError} that caused this {@link QuicException}. + * @return the {@link QuicTransportError} that caused this {@link QuicException} or {@code null} if + * it was caused by something different. */ + @Nullable public QuicTransportError error() { return error; } diff --git a/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/Quiche.java b/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/Quiche.java index aadc5eb8..1f29e633 100644 --- a/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/Quiche.java +++ b/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/Quiche.java @@ -889,7 +889,10 @@ static long getPrimitiveValue(ByteBuffer memory, int offset, int valueType) { static Exception convertToException(int result) { QuicTransportErrorHolder holder = ERROR_MAPPINGS.get(result); - assert holder != null; + if (holder == null) { + // There is no mapping to a transport error, it's something internal so throw it directly. + return new QuicException(QuicheError.valueOf(result).message()); + } Exception exception = new QuicException(holder.error + ": " + holder.quicheErrorName, holder.error); if (result == QUICHE_ERR_TLS_FAIL) { String lastSslError = BoringSSL.ERR_last_error(); diff --git a/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicheError.java b/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicheError.java index f6e752e4..7cfb6a51 100644 --- a/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicheError.java +++ b/codec-classes-quic/src/main/java/io/netty/incubator/codec/quic/QuicheError.java @@ -79,6 +79,4 @@ static QuicheError valueOf(int code) { } return errorCode; } - - }