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