mirror of
https://github.com/docker/compose.git
synced 2026-11-17 13:45:39 +00:00
CreateOptions.Recreate and RecreateDependencies are strings, and any value other than force or never silently behaved like diverged: a typo such as "forced" was accepted and did the opposite of what the caller meant. Add CreateOptions.Validate, which rejects such values with an InvalidOptionError matching the new ErrInvalidOption, and call it from Create and, through UpOptions.Validate, from Up, before anything is touched. The empty string keeps meaning diverged, and the Recreate* constants are unchanged, so existing callers are not affected. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
104 lines
3.8 KiB
Go
104 lines
3.8 KiB
Go
/*
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package api
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
const (
|
|
// ExitCodeLoginRequired exit code when command cannot execute because it requires cloud login
|
|
// This will be used by VSCode to detect when creating context if the user needs to login first
|
|
ExitCodeLoginRequired = 5
|
|
)
|
|
|
|
var (
|
|
// ErrNotFound is returned when an object is not found
|
|
ErrNotFound = errors.New("not found")
|
|
// ErrAlreadyExists is returned when an object already exists
|
|
ErrAlreadyExists = errors.New("already exists")
|
|
// ErrForbidden is returned when an operation is not permitted
|
|
ErrForbidden = errors.New("forbidden")
|
|
// ErrUnknown is returned when the error type is unmapped
|
|
ErrUnknown = errors.New("unknown")
|
|
// ErrNotImplemented is returned when a backend doesn't implement an action
|
|
ErrNotImplemented = errors.New("not implemented")
|
|
// ErrUnsupportedFlag is returned when a backend doesn't support a flag
|
|
ErrUnsupportedFlag = errors.New("unsupported flag")
|
|
// ErrCanceled is returned when the command was canceled by user
|
|
ErrCanceled = errors.New("canceled")
|
|
// ErrParsingFailed is returned when a string cannot be parsed
|
|
ErrParsingFailed = errors.New("parsing failed")
|
|
// ErrNoResources is returned when operation didn't selected any resource
|
|
ErrNoResources = errors.New("no resources")
|
|
// ErrIncompatibleOptions is returned when a set of options that cannot be
|
|
// honored together is requested. See IncompatibleOptionsError.
|
|
ErrIncompatibleOptions = errors.New("incompatible options")
|
|
// ErrInvalidOption is returned when an option is set to a value it does
|
|
// not accept. See InvalidOptionError.
|
|
ErrInvalidOption = errors.New("invalid option")
|
|
)
|
|
|
|
// IsNotFoundError returns true if the unwrapped error is ErrNotFound
|
|
func IsNotFoundError(err error) bool {
|
|
return errors.Is(err, ErrNotFound)
|
|
}
|
|
|
|
// IsAlreadyExistsError returns true if the unwrapped error is ErrAlreadyExists
|
|
func IsAlreadyExistsError(err error) bool {
|
|
return errors.Is(err, ErrAlreadyExists)
|
|
}
|
|
|
|
// IsForbiddenError returns true if the unwrapped error is ErrForbidden
|
|
func IsForbiddenError(err error) bool {
|
|
return errors.Is(err, ErrForbidden)
|
|
}
|
|
|
|
// IsUnknownError returns true if the unwrapped error is ErrUnknown
|
|
func IsUnknownError(err error) bool {
|
|
return errors.Is(err, ErrUnknown)
|
|
}
|
|
|
|
// IsErrUnsupportedFlag returns true if the unwrapped error is ErrUnsupportedFlag
|
|
func IsErrUnsupportedFlag(err error) bool {
|
|
return errors.Is(err, ErrUnsupportedFlag)
|
|
}
|
|
|
|
// IsErrNotImplemented returns true if the unwrapped error is ErrNotImplemented
|
|
func IsErrNotImplemented(err error) bool {
|
|
return errors.Is(err, ErrNotImplemented)
|
|
}
|
|
|
|
// IsErrParsingFailed returns true if the unwrapped error is ErrParsingFailed
|
|
func IsErrParsingFailed(err error) bool {
|
|
return errors.Is(err, ErrParsingFailed)
|
|
}
|
|
|
|
// IsErrCanceled returns true if the unwrapped error is ErrCanceled
|
|
func IsErrCanceled(err error) bool {
|
|
return errors.Is(err, ErrCanceled)
|
|
}
|
|
|
|
// IsErrIncompatibleOptions returns true if the unwrapped error is ErrIncompatibleOptions
|
|
func IsErrIncompatibleOptions(err error) bool {
|
|
return errors.Is(err, ErrIncompatibleOptions)
|
|
}
|
|
|
|
// IsErrInvalidOption returns true if the unwrapped error is ErrInvalidOption
|
|
func IsErrInvalidOption(err error) bool {
|
|
return errors.Is(err, ErrInvalidOption)
|
|
}
|