gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/pool/errors.go (about) 1 package pool 2 3 import "fmt" 4 5 type InvalidReferenceError struct { 6 CurRef int64 7 LastRef int64 8 } 9 10 func NewInvalidReferenceError(cur, last int64) InvalidReferenceError { 11 return InvalidReferenceError{CurRef: cur, LastRef: last} 12 } 13 14 func (e InvalidReferenceError) Error() string { 15 if e.CurRef > e.LastRef { 16 return fmt.Sprintf("非法的引用计数增加[%d -> %d]", e.LastRef, e.CurRef) 17 } else if e.LastRef < e.CurRef { 18 return fmt.Sprintf("非法的引用计数减少[%d -> %d]", e.LastRef, e.CurRef) 19 } else { 20 return fmt.Sprintf("非法的引用计数(%d)", e.CurRef) 21 } 22 } 23 24 type AllocError struct { 25 Target string 26 } 27 28 func NewAllocError(target string) error { 29 return AllocError{Target: target} 30 } 31 32 func (e AllocError) Error() string { 33 return fmt.Sprintf("申请%s失败", e.Target) 34 }