1/* 2 Copyright 2020 Docker Compose CLI authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15*/ 16 17package api 18 19import ( 20 "github.com/pkg/errors" 21) 22 23const ( 24 //ExitCodeLoginRequired exit code when command cannot execute because it requires cloud login 25 // This will be used by VSCode to detect when creating context if the user needs to login first 26 ExitCodeLoginRequired = 5 27) 28 29var ( 30 // ErrNotFound is returned when an object is not found 31 ErrNotFound = errors.New("not found") 32 // ErrAlreadyExists is returned when an object already exists 33 ErrAlreadyExists = errors.New("already exists") 34 // ErrForbidden is returned when an operation is not permitted 35 ErrForbidden = errors.New("forbidden") 36 // ErrUnknown is returned when the error type is unmapped 37 ErrUnknown = errors.New("unknown") 38 // ErrLoginFailed is returned when login failed 39 ErrLoginFailed = errors.New("login failed") 40 // ErrLoginRequired is returned when login is required for a specific action 41 ErrLoginRequired = errors.New("login required") 42 // ErrNotImplemented is returned when a backend doesn't implement 43 // an action 44 ErrNotImplemented = errors.New("not implemented") 45 // ErrUnsupportedFlag is returned when a backend doesn't support a flag 46 ErrUnsupportedFlag = errors.New("unsupported flag") 47 // ErrCanceled is returned when the command was canceled by user 48 ErrCanceled = errors.New("canceled") 49 // ErrParsingFailed is returned when a string cannot be parsed 50 ErrParsingFailed = errors.New("parsing failed") 51 // ErrWrongContextType is returned when the caller tries to get a context 52 // with the wrong type 53 ErrWrongContextType = errors.New("wrong context type") 54) 55 56// IsNotFoundError returns true if the unwrapped error is ErrNotFound 57func IsNotFoundError(err error) bool { 58 return errors.Is(err, ErrNotFound) 59} 60 61// IsAlreadyExistsError returns true if the unwrapped error is ErrAlreadyExists 62func IsAlreadyExistsError(err error) bool { 63 return errors.Is(err, ErrAlreadyExists) 64} 65 66// IsForbiddenError returns true if the unwrapped error is ErrForbidden 67func IsForbiddenError(err error) bool { 68 return errors.Is(err, ErrForbidden) 69} 70 71// IsUnknownError returns true if the unwrapped error is ErrUnknown 72func IsUnknownError(err error) bool { 73 return errors.Is(err, ErrUnknown) 74} 75 76// IsErrUnsupportedFlag returns true if the unwrapped error is ErrUnsupportedFlag 77func IsErrUnsupportedFlag(err error) bool { 78 return errors.Is(err, ErrUnsupportedFlag) 79} 80 81// IsErrNotImplemented returns true if the unwrapped error is ErrNotImplemented 82func IsErrNotImplemented(err error) bool { 83 return errors.Is(err, ErrNotImplemented) 84} 85 86// IsErrParsingFailed returns true if the unwrapped error is ErrParsingFailed 87func IsErrParsingFailed(err error) bool { 88 return errors.Is(err, ErrParsingFailed) 89} 90 91// IsErrCanceled returns true if the unwrapped error is ErrCanceled 92func IsErrCanceled(err error) bool { 93 return errors.Is(err, ErrCanceled) 94} 95