errors

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ErrConfigInvalid     = "ERR_CONFIG_INVALID"
	ErrConfigNotFound    = "ERR_CONFIG_NOT_FOUND"
	ErrServiceTimeout    = "ERR_SERVICE_TIMEOUT"
	ErrServiceFailed     = "ERR_SERVICE_FAILED"
	ErrServiceNotReady   = "ERR_SERVICE_NOT_READY"
	ErrServiceNotRunning = "ERR_SERVICE_NOT_RUNNING"
	ErrTestFailed        = "ERR_TEST_FAILED"
	ErrDockerConnection  = "ERR_DOCKER_CONNECTION"
	ErrDockerFailed      = "ERR_DOCKER_FAILED"
	ErrContainerFailed   = "ERR_CONTAINER_FAILED"
	ErrContainerForeign  = "ERR_CONTAINER_FOREIGN"
	ErrContainerExited   = "ERR_CONTAINER_EXITED"
	ErrProcessFailed     = "ERR_PROCESS_FAILED"
	ErrInvalidArgument   = "ERR_INVALID_ARGUMENT"
)

Error codes

Variables

This section is empty.

Functions

func Is

func Is(err error, code string) bool

Is reports whether any GTError in err's chain (including errors joined with errors.Join or wrapped with fmt.Errorf %w) has the given code.

Types

type GTError

type GTError struct {
	Code    string
	Message string
	Cause   error
	Context map[string]interface{}
}

GTError represents a gtool error with code and context

func New

func New(code, message string) *GTError

New creates a new GTError

Example
err := New(ErrConfigInvalid, "configuration is missing required field")
fmt.Println(err.Error())
Output:
[ERR_CONFIG_INVALID] configuration is missing required field

func Wrap

func Wrap(err error, code, message string) *GTError

Wrap wraps an error with a GTError

Example
originalErr := errors.New("file not found")
err := Wrap(originalErr, ErrConfigNotFound, "failed to load configuration")
fmt.Println(err.Error())
Output:
[ERR_CONFIG_NOT_FOUND] failed to load configuration: file not found

func (*GTError) Error

func (e *GTError) Error() string

Error implements the error interface

func (*GTError) Unwrap

func (e *GTError) Unwrap() error

Unwrap returns the underlying error

func (*GTError) WithContext

func (e *GTError) WithContext(key string, value interface{}) *GTError

WithContext adds context to the error

Example
err := New(ErrServiceFailed, "service failed to start")
err = err.WithContext("service", "couchbase")
err = err.WithContext("port", 8091)

fmt.Printf("Code: %s, Message: %s, Service: %s\n",
	err.Code, err.Message, err.Context["service"])
Output:
Code: ERR_SERVICE_FAILED, Message: service failed to start, Service: couchbase

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL