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" ErrProcessFailed = "ERR_PROCESS_FAILED" ErrInvalidArgument = "ERR_INVALID_ARGUMENT" )
Error codes
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GTError ¶
GTError represents a gtool error with code and context
func New ¶
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 ¶
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) WithContext ¶
WithContext adds context to the error
Example ¶
err := New(ErrServiceFailed, "service failed to start")
err.WithContext("service", "couchbase")
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
Click to show internal directories.
Click to hide internal directories.