github.com/apernet/quic-go@v0.43.1-0.20240515053213-5e9e635fd9f0/internal/qerr/error_codes.go (about) 1 package qerr 2 3 import ( 4 "crypto/tls" 5 "fmt" 6 ) 7 8 // TransportErrorCode is a QUIC transport error. 9 type TransportErrorCode uint64 10 11 // The error codes defined by QUIC 12 const ( 13 NoError TransportErrorCode = 0x0 14 InternalError TransportErrorCode = 0x1 15 ConnectionRefused TransportErrorCode = 0x2 16 FlowControlError TransportErrorCode = 0x3 17 StreamLimitError TransportErrorCode = 0x4 18 StreamStateError TransportErrorCode = 0x5 19 FinalSizeError TransportErrorCode = 0x6 20 FrameEncodingError TransportErrorCode = 0x7 21 TransportParameterError TransportErrorCode = 0x8 22 ConnectionIDLimitError TransportErrorCode = 0x9 23 ProtocolViolation TransportErrorCode = 0xa 24 InvalidToken TransportErrorCode = 0xb 25 ApplicationErrorErrorCode TransportErrorCode = 0xc 26 CryptoBufferExceeded TransportErrorCode = 0xd 27 KeyUpdateError TransportErrorCode = 0xe 28 AEADLimitReached TransportErrorCode = 0xf 29 NoViablePathError TransportErrorCode = 0x10 30 ) 31 32 func (e TransportErrorCode) IsCryptoError() bool { 33 return e >= 0x100 && e < 0x200 34 } 35 36 // Message is a description of the error. 37 // It only returns a non-empty string for crypto errors. 38 func (e TransportErrorCode) Message() string { 39 if !e.IsCryptoError() { 40 return "" 41 } 42 return tls.AlertError(e - 0x100).Error() 43 } 44 45 func (e TransportErrorCode) String() string { 46 switch e { 47 case NoError: 48 return "NO_ERROR" 49 case InternalError: 50 return "INTERNAL_ERROR" 51 case ConnectionRefused: 52 return "CONNECTION_REFUSED" 53 case FlowControlError: 54 return "FLOW_CONTROL_ERROR" 55 case StreamLimitError: 56 return "STREAM_LIMIT_ERROR" 57 case StreamStateError: 58 return "STREAM_STATE_ERROR" 59 case FinalSizeError: 60 return "FINAL_SIZE_ERROR" 61 case FrameEncodingError: 62 return "FRAME_ENCODING_ERROR" 63 case TransportParameterError: 64 return "TRANSPORT_PARAMETER_ERROR" 65 case ConnectionIDLimitError: 66 return "CONNECTION_ID_LIMIT_ERROR" 67 case ProtocolViolation: 68 return "PROTOCOL_VIOLATION" 69 case InvalidToken: 70 return "INVALID_TOKEN" 71 case ApplicationErrorErrorCode: 72 return "APPLICATION_ERROR" 73 case CryptoBufferExceeded: 74 return "CRYPTO_BUFFER_EXCEEDED" 75 case KeyUpdateError: 76 return "KEY_UPDATE_ERROR" 77 case AEADLimitReached: 78 return "AEAD_LIMIT_REACHED" 79 case NoViablePathError: 80 return "NO_VIABLE_PATH" 81 default: 82 if e.IsCryptoError() { 83 return fmt.Sprintf("CRYPTO_ERROR %#x", uint16(e)) 84 } 85 return fmt.Sprintf("unknown error code: %#x", uint16(e)) 86 } 87 }