github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/admin/errors.go (about) 1 package admin 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 // InvalidAdminReqError indicates that an admin request has failed validation, and 9 // the request will not be processed. All Validator functions must return this error 10 // if the request was invalid. 11 type InvalidAdminReqError struct { 12 Err error 13 } 14 15 func NewInvalidAdminReqErrorf(msg string, args ...any) InvalidAdminReqError { 16 return InvalidAdminReqError{ 17 Err: fmt.Errorf(msg, args...), 18 } 19 } 20 21 // NewInvalidAdminReqParameterError returns an InvalidAdminReqError indicating that 22 // a field of the request has an invalid value. 23 func NewInvalidAdminReqParameterError(field string, msg string, actualVal any) InvalidAdminReqError { 24 return NewInvalidAdminReqErrorf("invalid value for field '%s': %s. Got: %v", field, msg, actualVal) 25 } 26 27 // NewInvalidAdminReqFormatError returns an InvalidAdminReqError indicating that 28 // the request data format is invalid. 29 func NewInvalidAdminReqFormatError(msg string, args ...any) InvalidAdminReqError { 30 return NewInvalidAdminReqErrorf("invalid request data format: "+msg, args...) 31 } 32 33 func IsInvalidAdminParameterError(err error) bool { 34 var target InvalidAdminReqError 35 return errors.As(err, &target) 36 } 37 38 func (err InvalidAdminReqError) Error() string { 39 return err.Err.Error() 40 } 41 42 func (err InvalidAdminReqError) Unwrap() error { 43 return err.Err 44 }