Documentation
¶
Overview ¶
Package errors provides leightweight error handling and classification primitives.
The package defines blazingly fast classification system. A class is composed of the major, minor and index subclassifications. Each subclassifaction has different bitwise length with total of 32 bits. Thus a Class is a wrapper over uint32. A major is composed of 8, minor 10 and index of 14 bits.
Example: Class with decimal value of 44205263, in a binary form equals to
00000010101000101000010011001111 which decomposes into: 00000010 - major (8 bit) 1010001010 - minor (10 bit) 00010011001111 - index (14 bit)
The class concept was inspired by the need of multiple errors with the same logic but different messages.
The package provides simple error handling interfaces and functions. It allows to create simple and detailed classified errors.
Index ¶
- type Class
- func MustNewClass(mjr Major, mnr Minor, index Index) Class
- func MustNewClassWIndex(mjr Major, mnr Minor) Class
- func MustNewMajorClass(mjr Major) Class
- func MustNewMinorClass(mjr Major, mnr Minor) Class
- func NewClass(mjr Major, mnr Minor, index Index) (Class, error)
- func NewClassWIndex(mjr Major, mnr Minor) (Class, error)
- func NewMajorClass(mjr Major) (Class, error)
- func NewMinorClass(mjr Major, mnr Minor) (Class, error)
- type ClassError
- type DetailedError
- type Detailer
- type Index
- type Indexer
- type Major
- type Minor
- type MultiError
- type Operationer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Class ¶
type Class uint32
Class is the error classification model. It is composed of the major, minor and index subclassifications. Each subclassifaction is a different length number, where major is composed of 8, minor 10 and index of 14 bits. Example:
44205263 in a binary form is: 00000010101000101000010011001111 which decomposes into: 00000010 - major (8 bit) - 2 1010001010 - minor (10 bit) - 650 00010011001111 - index (14 bit) - 1231
Major should be a global scope division like 'Repository', 'Marshaler', 'Controller' etc. Minor should divide the 'major' into subclasses like the Repository filter builders, marshaler - invalid field etc. Index is the most precise classification - i.e. Repository - filter builder - unsupported operator.
func MustNewClass ¶
MustNewClass gets new class from the provided 'minor' and 'index'. Panics if any of the arguments is not valid or out of bands.
func MustNewClassWIndex ¶ added in v1.1.0
MustNewClassWIndex creates new 'mjr' Major, 'mnr' Minor 'index' and then a new Class for provided triplet. Panics on error.
func MustNewMajorClass ¶
MustNewMajorClass creates Class from the provided 'mjr' Major. This class contains zero valued 'Minor' and 'Index'. Panics if provided 'mjr' is invalid.
func MustNewMinorClass ¶
MustNewMinorClass creates a class from the provided 'mjr' Major and 'mnr' Minor. Panics when any of the provided arguments is invalid.
func NewClass ¶
NewClass gets new class from the provided 'minor' and 'index'. If any of the arguments is not valid or out of bands the function returns an error.
func NewClassWIndex ¶ added in v1.1.0
NewClassWIndex creates new index and class for provided 'mjr' Major and 'mnr' Minor. Returns error if any of the input values are not valid.
func NewMajorClass ¶
NewMajorClass creates Class from the provided 'mjr' Major. This class contains zero valued 'Minor' and 'Index'. Returns error if the 'mjr' is invalid.
func NewMinorClass ¶
NewMinorClass gets the class from provided 'minor'. The function gets minor's major and gets the major/minor class.
type ClassError ¶
ClassError is the interface used for all errors that uses classification system.
func New ¶
func New(c Class, msg string) ClassError
New creates simple ClassError for provided 'c' Class and 'msg' message.
func Newf ¶
func Newf(c Class, format string, args ...interface{}) ClassError
Newf creates simple formatted ClassError for provided 'c' Class, 'format' and arguments 'args'.
type DetailedError ¶
type DetailedError interface { ClassError Indexer Detailer Operationer }
DetailedError is the error that implements ClassError, Detailer, Indexer, Operationer interfaces.
func NewDet ¶
func NewDet(c Class, message string) DetailedError
NewDet creates DetailedError with given 'class' and message 'message'.
func NewDetf ¶
func NewDetf(c Class, format string, args ...interface{}) DetailedError
NewDetf creates DetailedError instance with provided 'class' with formatted message. DetailedError implements ClassError interface.
type Detailer ¶
type Detailer interface { // Details are human readable information about the error. Details() string // SetDetails sets the detail for given error. SetDetails(message string) // SetDetailsf sets formatted detail function. SetDetailsf(format string, args ...interface{}) // WrapDetails if Detailer contains any 'Details' then it would // be combined with the 'message'. Otherwise works as SetDetails. WrapDetails(message string) // WrapDetailsf if Detailer contains any 'Details' then it would // be combined with the formatted message. Otherwise works as SetDetailsf. WrapDetailsf(format string, args ...interface{}) }
Detailer is the interface that defines methods used for setting details (errors).
type Index ¶
type Index uint16
Index is a 14 bit length lowest level error classification. It defines the most accurate class division. It's maximum size gives 2^14 - 16384 - index combinations for each minor.
func MustNewIndex ¶
MustNewIndex creates new Index for the 'mjr' Major and 'mnr' Minor. Panics if 'mjr' or 'mnr' are not valid.
type Major ¶
type Major uint8
Major is the highest level subclassification. It is of maximum 8 bit size, which gives 2^8 - 256 combinations.
func MustNewMajor ¶ added in v1.2.0
func MustNewMajor() Major
MustNewMajor creates new major error classification. Panics if reached maximum number of possible majors.
type Minor ¶
type Minor uint16
Minor is mid level error subclassification. It is a 10 bit long value, which give 2^10 - 1024 - combinations for each major.
func MustNewMinor ¶
MustNewMinor creates new Minor error classification for provided 'mjr' Major. Panics if the 'mjr' is not valid.
type MultiError ¶
type MultiError []ClassError
MultiError is the slice of errors parsable into a single error.
func (MultiError) HasMajor ¶
func (m MultiError) HasMajor(mjr Major) bool
HasMajor checks if provided 'mjr' occurs in given multi error slice.
type Operationer ¶
type Operationer interface { // Operation gets the runtime information about the file:line and function // where the error was created. Operation() string // AppendOperation wraps the operation creating a chain of operations. AppendOperation(operation string) }
Operationer is enhanced error interface. It contains and allows to get the run time operation name.