github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/core/lease/errors.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package lease 5 6 import "github.com/juju/errors" 7 8 const ( 9 // ErrClaimDenied indicates that a Claimer.Claim() has been denied. 10 ErrClaimDenied = errors.ConstError("lease claim denied") 11 12 // ErrNotHeld indicates that some holder does not hold some lease. 13 ErrNotHeld = errors.ConstError("lease not held") 14 15 // ErrWaitCancelled is returned by Claimer.WaitUntilExpired if the 16 // cancel channel is closed. 17 ErrWaitCancelled = errors.ConstError("waiting for lease cancelled by client") 18 19 // ErrInvalid indicates that a Store operation failed because latest state 20 // indicates that it's a logical impossibility. It's a short-range signal to 21 // calling code only; that code should never pass it on, but should inspect 22 // the Store's updated Leases() and either attempt a new operation or return 23 // a new error at a suitable level of abstraction. 24 ErrInvalid = errors.ConstError("invalid lease operation") 25 26 // ErrHeld indicates that a claim operation was impossible to fulfill 27 // because the lease has been claimed on behalf of another entity. 28 // This operation should not be retried. 29 ErrHeld = errors.ConstError("lease already held") 30 31 // ErrTimeout indicates that a Store operation failed because it 32 // couldn't update the underlying lease information. This is probably 33 // a transient error due to changes in the cluster, and indicates that 34 // the operation should be retried. 35 ErrTimeout = errors.ConstError("lease operation timed out") 36 37 // ErrAborted indicates that the stop channel returned before the operation 38 // succeeded or failed. 39 ErrAborted = errors.ConstError("lease operation aborted") 40 ) 41 42 // IsInvalid returns whether the specified error represents ErrInvalid 43 // (even if it's wrapped). 44 func IsInvalid(err error) bool { 45 return errors.Cause(err) == ErrInvalid 46 } 47 48 // IsHeld returns whether the specified error represents ErrHeld 49 // (even if it's wrapped). 50 func IsHeld(err error) bool { 51 return errors.Cause(err) == ErrHeld 52 } 53 54 // IsTimeout returns whether the specified error represents ErrTimeout 55 // (even if it's wrapped). 56 func IsTimeout(err error) bool { 57 return errors.Cause(err) == ErrTimeout 58 } 59 60 // IsAborted returns whether the specified error represents ErrAborted 61 // (even if it's wrapped). 62 func IsAborted(err error) bool { 63 return errors.Cause(err) == ErrAborted 64 } 65 66 // IsNotHeld returns whether the specified error represents ErrNotHeld 67 // (even if it's wrapped). 68 func IsNotHeld(err error) bool { 69 return errors.Cause(err) == ErrNotHeld 70 }