Documentation
¶
Index ¶
- Constants
- Variables
- func GetExitCodeForError(err error) int
- func IsAPIError(err error) bool
- func IsAuthenticationError(err error) bool
- func IsConfigurationError(err error) bool
- func IsNotFound(err error) bool
- func IsPermissionDeniedError(err error) bool
- func IsUserAborted(err error) bool
- func IsValidationError(err error) bool
- func MessageForError(err error) string
- func NewAPIError(err error, details string, suggestions ...string) error
- func NewAuthenticationError(err error, details string, suggestions ...string) error
- func NewConfigurationError(err error, details string, suggestions ...string) error
- func NewInternalError(err error, details string, suggestions ...string) error
- func NewPermissionDeniedError(err error, details string, suggestions ...string) error
- func NewResourceNotFoundError(err error, details string, suggestions ...string) error
- func NewUserAbortedError(err error, details string, suggestions ...string) error
- func NewValidationError(err error, details string, suggestions ...string) error
- func WithDetails(err error, details string) error
- func WithSuggestions(err error, suggestions ...string) error
- func WrapAPIError(err error, operation string) error
- type APIErrorResponse
- type Error
- type Handler
- func (h *Handler) Handle(err error)
- func (h *Handler) HandleWithDetails(err error, operation string)
- func (h *Handler) PrintWarning(format string, args ...interface{})
- func (h *Handler) WithExitFunc(f func(int)) *Handler
- func (h *Handler) WithVerbose(v bool) *Handler
- func (h *Handler) WithWriter(w io.Writer) *Handler
Constants ¶
const ( ExitCodeSuccess = 0 ExitCodeGenericError = 1 ExitCodeValidationError = 2 ExitCodeAPIError = 3 ExitCodeNotFoundError = 4 ExitCodePermissionError = 5 ExitCodeConfigError = 6 ExitCodeAuthError = 7 ExitCodeInternalError = 8 ExitCodeUserAbortedError = 130 // Same as Ctrl+C in bash )
Exit codes for different error types
Variables ¶
var ( // ErrConfiguration indicates an error in the user's configuration ErrConfiguration = errors.New("configuration error") // ErrValidation indicates invalid input from the user ErrValidation = errors.New("validation error") // ErrAPI indicates an error from the Buildkite API ErrAPI = errors.New("API error") // ErrResourceNotFound indicates a requested resource was not found ErrResourceNotFound = errors.New("resource not found") // ErrPermissionDenied indicates the user lacks permission ErrPermissionDenied = errors.New("permission denied") // ErrAuthentication indicates an issue with authentication ErrAuthentication = errors.New("authentication error") // ErrInternal indicates an internal error in the CLI ErrInternal = errors.New("internal error") // ErrUserAborted indicates the user has canceled an operation ErrUserAborted = errors.New("user aborted") )
Standard error types that can be used to categorize errors
Functions ¶
func GetExitCodeForError ¶
GetExitCodeForError returns the exit code for a given error
func IsAPIError ¶
IsAPIError returns true if the error indicates an API failure
func IsAuthenticationError ¶
IsAuthenticationError returns true if the error indicates an authentication failure
func IsConfigurationError ¶
IsConfigurationError returns true if the error indicates a configuration issue
func IsNotFound ¶
IsNotFound returns true if the error indicates a resource was not found
func IsPermissionDeniedError ¶
IsPermissionDeniedError returns true if the error indicates a permission issue
func IsUserAborted ¶
IsUserAborted returns true if the error indicates the user aborted the operation
func IsValidationError ¶
IsValidationError returns true if the error indicates a validation failure
func MessageForError ¶
MessageForError returns a formatted message for an error without exiting
func NewAPIError ¶
NewAPIError creates a new API error
func NewAuthenticationError ¶
NewAuthenticationError creates a new authentication error
func NewConfigurationError ¶
NewConfigurationError creates a new configuration error
func NewInternalError ¶
NewInternalError creates a new internal error
func NewPermissionDeniedError ¶
NewPermissionDeniedError creates a new permission denied error
func NewResourceNotFoundError ¶
NewResourceNotFoundError creates a new resource not found error
func NewUserAbortedError ¶
NewUserAbortedError creates a new user aborted error
func NewValidationError ¶
NewValidationError creates a new validation error
func WithDetails ¶
WithDetails adds details to an existing error
func WithSuggestions ¶
WithSuggestions adds suggestions to an existing error
func WrapAPIError ¶
WrapAPIError wraps an API error with appropriate context and suggestions
Types ¶
type APIErrorResponse ¶
type APIErrorResponse struct {
Message string `json:"message"`
Errors []string `json:"errors,omitempty"`
Details map[string]string `json:"details,omitempty"`
}
APIErrorResponse represents a Buildkite API error response
type Error ¶
type Error struct {
// Original is the underlying error
Original error
// Category is the broad category of the error
Category error
// Details contains additional detail about the error
Details string
// Suggestions provides hints on how to fix the error
Suggestions []string
}
Error represents a CLI error with context
func (*Error) FormattedError ¶
FormattedError returns a formatted multi-line error message suitable for display
type Handler ¶
type Handler struct {
// Writer is where error messages will be written
Writer io.Writer
// ExitFunc is the function called to exit the program with a specific code
ExitFunc func(int)
// Verbose enables more detailed error messages
Verbose bool
}
Handler processes errors from commands and formats them appropriately
func (*Handler) HandleWithDetails ¶
HandleWithDetails processes an error with additional contextual details
func (*Handler) PrintWarning ¶
PrintWarning prints a warning message
func (*Handler) WithExitFunc ¶
WithExitFunc sets the exit function
func (*Handler) WithVerbose ¶
WithVerbose sets the verbose flag