Skip to content

Commit

Permalink
Correctly translate quiche error to QuicException that have no transp… (
Browse files Browse the repository at this point in the history
#736)

…ort 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 #735
  • Loading branch information
normanmaurer authored Jul 19, 2024
1 parent 156ce3e commit 7af317e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
*/
package io.netty.incubator.codec.quic;

import org.jetbrains.annotations.Nullable;

/**
* Exception produced while processing {@code QUIC}.
*/
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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,4 @@ static QuicheError valueOf(int code) {
}
return errorCode;
}


}

0 comments on commit 7af317e

Please sign in to comment.