Documentation ¶
Index ¶
- Constants
- Variables
- func CloneByteSlice(x []byte) []byte
- func FmtError(e error) string
- func FmtErrors(es []error) string
- func GetNestedError(e error) error
- func IsTemporaryErr(e error) bool
- func IsTimeoutErr(e error) bool
- func NewBasicError(msg ErrMsg, e error, logCtx ...interface{}) error
- func TypeOf(v interface{}) string
- type BasicError
- type ByteOrderN
- type ErrMsg
- type ErrorMsger
- type ErrorNester
- type Extension
- type ExtnBase
- type ExtnType
- type IFIDType
- type L4ProtocolType
- type MultiError
- type Payload
- type RawBytes
- type Temporary
- type Timeout
Examples ¶
Constants ¶
const ( // LineLen is the number of bytes that all SCION headers are padded to a multiple of. LineLen = 8 MinMTU = 1280 MaxMTU = (1 << 16) - 1 TimeFmt = "2006-01-02 15:04:05.000000-0700" TimeFmtSecs = "2006-01-02 15:04:05-0700" )
const ( BR = "BR" CS = "CS" SB = "SB" RS = "RS" SIG = "SIG" CPService = "Control Plane Service" )
const ( // Maximum allowed hop-by-hop extensions, excluding a potential leading SCMP extension. ExtnMaxHBH = 3 ExtnSubHdrLen = 3 ExtnFirstLineLen = LineLen - ExtnSubHdrLen )
const IFIDBytes = 8
Variables ¶
var ( Order ByteOrderN = newBigEndianN() NativeOrder ByteOrderN IsBigEndian bool )
var ( ExtnSCMPType = ExtnType{HopByHopClass, 0} ExtnOneHopPathType = ExtnType{HopByHopClass, 1} ExtnSIBRAType = ExtnType{HopByHopClass, 2} ExtnPathTransType = ExtnType{End2EndClass, 0} ExtnPathProbeType = ExtnType{End2EndClass, 1} ExtnSCIONPacketSecurityType = ExtnType{End2EndClass, 2} // ExtnE2EDebugType can be used to trace specific packets through the // network. This is intended only for local use, and is not a recognized // SCION extension. ExtnE2EDebugType = ExtnType{End2EndClass, 254} )
var L4Protocols = map[L4ProtocolType]bool{ L4SCMP: true, L4TCP: true, L4UDP: true, }
Functions ¶
func CloneByteSlice ¶ added in v0.4.0
func FmtError ¶
FmtError formats e for logging. It walks through all nested errors, putting each on a new line, and indenting multi-line errors.
func GetNestedError ¶
GetNestedError returns the nested error, if any. Returns nil otherwise.
func IsTemporaryErr ¶
IsTemporaryErr determines if e is a temporary Error. As a fall-back, if e implements ErrorNester, IsTemporaryErr recurses on the nested error. Otherwise returns false.
func IsTimeoutErr ¶
IsTimeoutErr determines if e is a temporary Error. As a fall-back, if e implements ErrorNester, IsTimeoutErr recurses on the nested error. Otherwise returns false.
func NewBasicError ¶
NewBasicError creates a new BasicError, with e as the embedded error (can be nil), with logCtx being a list of string/val pairs. These key/value pairs should contain all context-dependent information: 'msg' argument itself should be a constant string.
Types ¶
type BasicError ¶
type BasicError struct { // Error message Msg ErrMsg // Nested error, if any. Err error // contains filtered or unexported fields }
BasicError is a simple error type that implements ErrorMsger and ErrorNester, and can contain context (slice of [string, val, string, val...]) for logging purposes.
func (BasicError) Error ¶
func (be BasicError) Error() string
func (BasicError) GetErr ¶
func (be BasicError) GetErr() error
func (BasicError) GetMsg ¶
func (be BasicError) GetMsg() string
func (BasicError) Is ¶ added in v0.4.0
func (be BasicError) Is(err error) bool
Is returns whether this error is the same error as err, or in case err is a ErrMsg whether the message is equal.
func (BasicError) TopError ¶
func (be BasicError) TopError() string
func (BasicError) Unwrap ¶ added in v0.4.0
func (be BasicError) Unwrap() error
Unwrap returns the next error in the error chain, or nil if there is none.
type ByteOrderN ¶
type ErrMsg ¶ added in v0.4.0
type ErrMsg string
ErrMsg should be used for error string constants. The constant can then be used for Is checking in the calling code.
Example ¶
var SomeErr ErrMsg = "this is the error msg" fmt.Println(errors.Is(NewBasicError(SomeErr, nil, "ctx", 1), SomeErr))
Output: true
type ErrorMsger ¶
ErrorMsger allows extracting the message from an error. This means a caller can determine the type of error by comparing the returned message with a const error string. E.g.:
if GetErrorMsg(err) == addr.ErrorBadHostAddrType { // Handle bad host addr error }
type ErrorNester ¶
type ErrorNester interface { error TopError() string // should not include the nested error GetErr() error }
ErrorNester allows recursing into nested errors.
type ExtnBase ¶
type ExtnBase interface { // Length in bytes, excluding 3B subheader Len() int Class() L4ProtocolType Type() ExtnType fmt.Stringer }
type ExtnType ¶
type ExtnType struct { Class L4ProtocolType Type uint8 }
type IFIDType ¶
type IFIDType uint64
IFIDType is the type for interface IDs.
func (*IFIDType) UnmarshalJSON ¶ added in v0.5.0
UnmarshalJSON unmarshals the JSON data into the IfID.
func (*IFIDType) UnmarshalText ¶ added in v0.4.0
UnmarshalText unmarshals the text into the IfID.
type L4ProtocolType ¶
type L4ProtocolType uint8
const ( L4None L4ProtocolType = 0 L4SCMP L4ProtocolType = 1 L4TCP L4ProtocolType = 6 L4UDP L4ProtocolType = 17 HopByHopClass L4ProtocolType = 0 End2EndClass L4ProtocolType = 222 )
func (L4ProtocolType) String ¶
func (p L4ProtocolType) String() string
type MultiError ¶ added in v0.4.0
type MultiError []error
MultiError is a slice of errors
func (MultiError) ToError ¶ added in v0.4.0
func (be MultiError) ToError() error
ToError returns the object as error interface implementation.
type Temporary ¶
Temporary allows signalling of a temporary error. Based on https://golang.org/pkg/net/#Error
type Timeout ¶
Timeout allows signalling of a timeout error. Based on https://golang.org/pkg/net/#Error