github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/environs/errors.go (about) 1 // Copyright 2011, 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package environs 5 6 import ( 7 "github.com/juju/errors" 8 ) 9 10 var ( 11 ErrNotBootstrapped = errors.New("model is not bootstrapped") 12 ErrNoInstances = errors.NotFoundf("instances") 13 ErrPartialInstances = errors.New("only some instances were found") 14 ) 15 16 // AvailabilityZoneError provides an interface for compute providers 17 // to indicate whether or not an error is specific to, or independent 18 // of, any particular availability zone. 19 type AvailabilityZoneError interface { 20 error 21 22 // AvailabilityZoneIndependent reports whether or not the 23 // error is related to a specific availability zone. 24 AvailabilityZoneIndependent() bool 25 } 26 27 // IsAvailabilityZoneIndependent reports whether or not the given error, 28 // or its cause, is independent of any particular availability zone. 29 // Juju uses this to decide whether or not to attempt the failed operation 30 // in another availability zone; zone-independent failures will not be 31 // reattempted. 32 // 33 // If the error implements AvailabilityZoneError, then the result of 34 // calling its AvailabilityZoneIndependent method will be returned; 35 // otherwise this function returns false. That is, errors are assumed 36 // to be specific to an availability zone by default, so that they can 37 // be retried in another availability zone. 38 func IsAvailabilityZoneIndependent(err error) bool { 39 if err, ok := errors.Cause(err).(AvailabilityZoneError); ok { 40 return err.AvailabilityZoneIndependent() 41 } 42 return false 43 }