git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/errors.go (about) 1 package client 2 3 import ( 4 "fmt" 5 6 apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" 7 ) 8 9 // wrapsErrType returns true if any error in the error tree of err is of type E. 10 func wrapsErrType[E error](err error) bool { 11 switch e := err.(type) { 12 case E: 13 return true 14 case interface{ Unwrap() error }: 15 return wrapsErrType[E](e.Unwrap()) 16 case interface{ Unwrap() []error }: 17 for _, ei := range e.Unwrap() { 18 if wrapsErrType[E](ei) { 19 return true 20 } 21 } 22 return false 23 default: 24 return false 25 } 26 } 27 28 // IsErrContainerNotFound checks if err corresponds to FrostFS status 29 // return corresponding to missing container. Supports wrapped errors. 30 func IsErrContainerNotFound(err error) bool { 31 return wrapsErrType[*apistatus.ContainerNotFound](err) 32 } 33 34 // IsErrEACLNotFound checks if err corresponds to FrostFS status 35 // return corresponding to missing eACL table. Supports wrapped errors. 36 func IsErrEACLNotFound(err error) bool { 37 return wrapsErrType[*apistatus.EACLNotFound](err) 38 } 39 40 // IsErrObjectNotFound checks if err corresponds to FrostFS status 41 // return corresponding to missing object. Supports wrapped errors. 42 func IsErrObjectNotFound(err error) bool { 43 return wrapsErrType[*apistatus.ObjectNotFound](err) 44 } 45 46 // IsErrObjectAlreadyRemoved checks if err corresponds to FrostFS status 47 // return corresponding to already removed object. Supports wrapped errors. 48 func IsErrObjectAlreadyRemoved(err error) bool { 49 return wrapsErrType[*apistatus.ObjectAlreadyRemoved](err) 50 } 51 52 // IsErrSessionExpired checks if err corresponds to FrostFS status return 53 // corresponding to expired session. Supports wrapped errors. 54 func IsErrSessionExpired(err error) bool { 55 return wrapsErrType[*apistatus.SessionTokenExpired](err) 56 } 57 58 // IsErrSessionNotFound checks if err corresponds to FrostFS status return 59 // corresponding to missing session. Supports wrapped errors. 60 func IsErrSessionNotFound(err error) bool { 61 return wrapsErrType[*apistatus.SessionTokenNotFound](err) 62 } 63 64 // IsErrAPEManagerAccessDenied checks if err corresponds to FrostFS status return 65 // corresponding to apemanager access deny. Supports wrapped errors. 66 func IsErrAPEManagerAccessDenied(err error) bool { 67 return wrapsErrType[*apistatus.APEManagerAccessDenied](err) 68 } 69 70 // IsErrNodeUnderMaintenance checks if err corresponds to FrostFS status return 71 // corresponding to nodes being under maintenance. Supports wrapped errors. 72 func IsErrNodeUnderMaintenance(err error) bool { 73 return wrapsErrType[*apistatus.NodeUnderMaintenance](err) 74 } 75 76 // returns error describing missing field with the given name. 77 func newErrMissingResponseField(name string) error { 78 return fmt.Errorf("missing %s field in the response", name) 79 } 80 81 // returns error describing invalid field (according to the FrostFS protocol) 82 // with the given name and format violation err. 83 func newErrInvalidResponseField(name string, err error) error { 84 return fmt.Errorf("invalid %s field in the response: %w", name, err) 85 }