ostree: rename errors and introduce ParameterComboError
Shorter and clearer error types. - InvalidParameterError is now RefError. It is returned when a ref (the new ref or the parent ref) is invalid. - The ResolveRefError is not renamed. It is returned when a ref can't be resolved (e.g., ref not found at URL). New error type ParameterComboError. It is returned when a parent ref is specified but no URL, which is an invalid parameter combination.
This commit is contained in:
parent
36d8cd1dd2
commit
9e0af86775
3 changed files with 21 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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...)}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue