github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/storage/errors/errors.go (about) 1 package errors 2 3 import ( 4 stdErrors "errors" 5 "fmt" 6 ) 7 8 type Unwrappable interface { 9 Unwrap() error 10 } 11 12 type RetryableConflictError interface { 13 IsRetryableConflict() bool 14 15 Unwrappable 16 error 17 } 18 19 func IsRetryableConflictError(originalErr error) bool { 20 if originalErr == nil { 21 return false 22 } 23 24 currentErr := originalErr 25 for { 26 var retryable RetryableConflictError 27 if !stdErrors.As(currentErr, &retryable) { 28 return false 29 } 30 31 if retryable.IsRetryableConflict() { 32 return true 33 } 34 35 currentErr = retryable.Unwrap() 36 } 37 } 38 39 type retryableConflictError struct { 40 error 41 } 42 43 func NewRetryableConflictError( 44 msg string, 45 vals ...interface{}, 46 ) error { 47 return &retryableConflictError{ 48 error: fmt.Errorf(msg, vals...), 49 } 50 } 51 52 func (retryableConflictError) IsRetryableConflict() bool { 53 return true 54 } 55 56 func (err *retryableConflictError) Unwrap() error { 57 return err.error 58 }