Repository: netty/netty
File: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/Quiche.java (Java)

Code before:
                new QuicTransportErrorHolder(QuicTransportError.KEY_UPDATE_ERROR, "QUICHE_ERR_KEY_UPDATE"));

        // Should the code be something different ?
        ERROR_MAPPINGS.put(QUICHE_ERR_TLS_FAIL,
                new QuicTransportErrorHolder(QuicTransportError.valueOf(0x0100), "QUICHE_ERR_TLS_FAIL"));
        ERROR_MAPPINGS.put(QUICHE_ERR_CRYPTO_FAIL,
                new QuicTransportErrorHolder(QuicTransportError.valueOf(0x0100), "QUICHE_ERR_CRYPTO_FAIL"));

        ERROR_MAPPINGS.put(QUICHE_ERR_BUFFER_TOO_SHORT,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_BUFFER_TOO_SHORT"));
        ERROR_MAPPINGS.put(QUICHE_ERR_UNKNOWN_VERSION,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_UNKNOWN_VERSION"));
        ERROR_MAPPINGS.put(QUICHE_ERR_INVALID_PACKET,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_INVALID_PACKET"));
        ERROR_MAPPINGS.put(QUICHE_ERR_INVALID_STATE,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_INVALID_STATE"));
        ERROR_MAPPINGS.put(QUICHE_ERR_CONGESTION_CONTROL,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_CONGESTION_CONTROL"));
        ERROR_MAPPINGS.put(QUICHE_ERR_STREAM_STOPPED,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_STREAM_STOPPED"));
        ERROR_MAPPINGS.put(QUICHE_ERR_OUT_OF_IDENTIFIERS,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_OUT_OF_IDENTIFIERS"));
    }

    static Exception convertToException(int result) {
        return convertToException(result, -1L);
    }

    static Exception convertToException(int result, long code) {
        QuicTransportErrorHolder holder = ERROR_MAPPINGS.get(result);
        if (holder == null) {
            // There is no mapping to a transport error, it's something internal so throw it directly.
            QuicheError error = QuicheError.valueOf(result);
            switch (error) {
                case STREAM_RESET:
                    return new QuicStreamResetException(error.message(), code);
                case STREAM_STOPPED:
                    return new QuicStreamException(error.message());
                default:
                    return new QuicException(error.message());
            }
        }
        Exception exception = new QuicException(holder.error + ": " + holder.quicheErrorName, holder.error);
        if (result == QUICHE_ERR_TLS_FAIL) {
            String lastSslError = BoringSSL.ERR_last_error();
            final SSLHandshakeException sslExc = new SSLHandshakeException(lastSslError);
            sslExc.initCause(exception);
            return sslExc;
        }
        if (result == QUICHE_ERR_CRYPTO_FAIL) {
            return new SSLException(exception);

Review comment (suggestion):
nit. 
```suggestion
        return convertToException(result, -1);
```

Code after:
                new QuicTransportErrorHolder(QuicTransportError.CRYPTO_BUFFER_EXCEEDED,
                        "QUICHE_ERR_CRYPTO_BUFFER_EXCEEDED"));
        ERROR_MAPPINGS.put(QUICHE_ERR_KEY_UPDATE,
                new QuicTransportErrorHolder(QuicTransportError.KEY_UPDATE_ERROR, "QUICHE_ERR_KEY_UPDATE"));

        // Should the code be something different ?
        ERROR_MAPPINGS.put(QUICHE_ERR_TLS_FAIL,
                new QuicTransportErrorHolder(QuicTransportError.valueOf(0x0100), "QUICHE_ERR_TLS_FAIL"));
        ERROR_MAPPINGS.put(QUICHE_ERR_CRYPTO_FAIL,
                new QuicTransportErrorHolder(QuicTransportError.valueOf(0x0100), "QUICHE_ERR_CRYPTO_FAIL"));

        ERROR_MAPPINGS.put(QUICHE_ERR_BUFFER_TOO_SHORT,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_BUFFER_TOO_SHORT"));
        ERROR_MAPPINGS.put(QUICHE_ERR_UNKNOWN_VERSION,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_UNKNOWN_VERSION"));
        ERROR_MAPPINGS.put(QUICHE_ERR_INVALID_PACKET,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_INVALID_PACKET"));
        ERROR_MAPPINGS.put(QUICHE_ERR_INVALID_STATE,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_INVALID_STATE"));
        ERROR_MAPPINGS.put(QUICHE_ERR_CONGESTION_CONTROL,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_CONGESTION_CONTROL"));
        ERROR_MAPPINGS.put(QUICHE_ERR_STREAM_STOPPED,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_STREAM_STOPPED"));
        ERROR_MAPPINGS.put(QUICHE_ERR_OUT_OF_IDENTIFIERS,
                new QuicTransportErrorHolder(QuicTransportError.PROTOCOL_VIOLATION, "QUICHE_ERR_OUT_OF_IDENTIFIERS"));
    }

    static Exception convertToException(int result) {
        return convertToException(result, -1);
    }

    static Exception convertToException(int result, long code) {
        QuicTransportErrorHolder holder = ERROR_MAPPINGS.get(result);
        if (holder == null) {
            // There is no mapping to a transport error, it's something internal so throw it directly.
            QuicheError error = QuicheError.valueOf(result);
            if (error == STREAM_RESET) {
                return new QuicStreamResetException(error.message(), code);
            } else {
                return new QuicException(error.message());
            }
        }
        Exception exception = new QuicException(holder.error + ": " + holder.quicheErrorName, holder.error);
        if (result == QUICHE_ERR_TLS_FAIL) {
            String lastSslError = BoringSSL.ERR_last_error();
            final SSLHandshakeException sslExc = new SSLHandshakeException(lastSslError);
            sslExc.initCause(exception);
            return sslExc;
        }
        if (result == QUICHE_ERR_CRYPTO_FAIL) {
            return new SSLException(exception);