diff --git a/internal/cloudapi/v2/v2.go b/internal/cloudapi/v2/v2.go index 9b22b10da..66b91b9d5 100644 --- a/internal/cloudapi/v2/v2.go +++ b/internal/cloudapi/v2/v2.go @@ -286,7 +286,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error { } if imageOptions.OSTree, err = ostree.ResolveParams(ostreeOptions, imageType.OSTreeRef()); err != nil { switch v := err.(type) { - case ostree.InvalidParameterError: + case ostree.RefError: return HTTPError(ErrorInvalidOSTreeRef) case ostree.ResolveRefError: return HTTPErrorWithInternal(ErrorInvalidOSTreeRepo, v) diff --git a/internal/ostree/errors.go b/internal/ostree/errors.go index ac7aa8abd..2c32d3678 100644 --- a/internal/ostree/errors.go +++ b/internal/ostree/errors.go @@ -20,16 +20,28 @@ func NewResolveRefError(msg string, args ...interface{}) ResolveRefError { // InvalidParamsError is returned when a parameter is invalid (e.g., malformed // or contains illegal characters). -type InvalidParameterError struct { +type RefError struct { msg string } -func (e InvalidParameterError) Error() string { +func (e RefError) Error() string { return e.msg } -// NewInvalidParameterError creates and returns a new InvalidParameterError +// NewRefError creates and returns a new InvalidParameterError // with a given formatted message. -func NewInvalidParameterError(msg string, args ...interface{}) InvalidParameterError { - return InvalidParameterError{msg: fmt.Sprintf(msg, args...)} +func NewRefError(msg string, args ...interface{}) RefError { + return RefError{msg: fmt.Sprintf(msg, args...)} +} + +type ParameterComboError struct { + msg string +} + +func (e ParameterComboError) Error() string { + return e.msg +} + +func NewParameterComboError(msg string, args ...interface{}) ParameterComboError { + return ParameterComboError{msg: fmt.Sprintf(msg, args...)} } diff --git a/internal/ostree/ostree.go b/internal/ostree/ostree.go index 9d7e8dab9..3bee97715 100644 --- a/internal/ostree/ostree.go +++ b/internal/ostree/ostree.go @@ -62,17 +62,17 @@ func ResolveParams(params RequestParams, defaultRef string) (RequestParams, erro if resolved.Ref == "" { resolved.Ref = defaultRef } else if !VerifyRef(params.Ref) { // only verify if specified in params - return resolved, NewInvalidParameterError("Invalid ostree ref %q", params.Ref) + return resolved, NewRefError("Invalid ostree ref %q", params.Ref) } if params.Parent != "" { // parent must also be a valid ref if !VerifyRef(params.Parent) { - return resolved, NewInvalidParameterError("Invalid ostree parent ref %q", params.Parent) + return resolved, NewRefError("Invalid ostree parent ref %q", params.Parent) } if params.URL == "" { // specifying parent ref also requires URL - return resolved, NewInvalidParameterError("ostree parent ref specified, but no URL to retrieve it") + return resolved, NewParameterComboError("ostree parent ref specified, but no URL to retrieve it") } }