github.com/muyo/sno@v1.2.1/errors.go (about) 1 package sno 2 3 import "fmt" 4 5 const ( 6 errInvalidDataSizeMsg = "sno: unrecognized data size" 7 errInvalidTypeFmt = "sno: unrecognized data type: %T" 8 errInvalidSequenceBoundsFmt = "sno: %s; min: %d, sequence: %d, max: %d, pool: %d" 9 errSequenceBoundsIdenticalMsg = "sno: sequence bounds are identical - need a sequence pool with a capacity of at least 4" 10 errSequenceUnderflowsBound = "sno: current sequence underflows the given lower bound" 11 errSequencePoolTooSmallMsg = "sno: generators require a sequence pool with a capacity of at least 4" 12 errPartitionPoolExhaustedMsg = "sno: process exceeded maximum number of possible defaults-configured generators" 13 ) 14 15 // InvalidDataSizeError gets returned when attempting to unmarshal or decode an ID from data that 16 // is not nil and not of a size of: SizeBinary, SizeEncoded nor 0. 17 type InvalidDataSizeError struct { 18 Size int 19 } 20 21 func (e *InvalidDataSizeError) Error() string { return errInvalidDataSizeMsg } 22 23 // InvalidTypeError gets returned when attempting to scan a value that is neither... 24 // - a string 25 // - a byte slice 26 // - nil 27 // ... into an ID via ID.Scan(). 28 type InvalidTypeError struct { 29 Value interface{} 30 } 31 32 func (e *InvalidTypeError) Error() string { 33 return fmt.Sprintf(errInvalidTypeFmt, e.Value) 34 } 35 36 // InvalidSequenceBoundsError gets returned when a Generator gets seeded with sequence boundaries 37 // which are invalid, e.g. the pool is too small or the current sequence overflows the bounds. 38 type InvalidSequenceBoundsError struct { 39 Cur uint32 40 Min uint16 41 Max uint16 42 Msg string 43 } 44 45 func (e *InvalidSequenceBoundsError) Error() string { 46 return fmt.Sprintf(errInvalidSequenceBoundsFmt, e.Msg, e.Min, e.Cur, e.Max, e.Max-e.Min+1) 47 } 48 49 // PartitionPoolExhaustedError gets returned when attempting to create more than MaxPartition (65535) 50 // Generators using the default configuration (eg. without snapshots). 51 // 52 // Should you ever run into this, please consult the docs on the genPartition() internal function. 53 type PartitionPoolExhaustedError struct{} 54 55 func (e *PartitionPoolExhaustedError) Error() string { return errPartitionPoolExhaustedMsg }