Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Errors

Convenience functions for one-liners for building stacks of errors, within built-in error interface. Also handle appending to error with dual-output functions.

e.g.

ifv, err:=someFunc(); err!=nil {
err=fmt.Errorf("Error doing <OPERATION> : %v\n", err)
returninterface{}, err
} else...

becomes

import"github.com/noahhai/errors"returnerrors.GetFromTupleAdd("Error during <OPERATION>")(someFunc())

Example

import sysErrors "errors"import"github.com/noahhai/errors"mockApiFunc:=func() error {
returnsysErrors.New("unexpected column found")
}
modelFunc:=func() *errors.Error {
returnerrors.From(mockApiFunc()).Add("failed to upsert value")
}
businessFunc:=func() *errors.Error {
returnmodelFunc().AddF("failed to perform daily sync of customer '%d'", 35)
}
// consumehandlerFunc:=func() {
iferr:=businessFunc(); err!=nil {
fmt.Println("Error handling request")
fmt.Println("Error: ")
fmt.Println(err)
fmt.Println()
fmt.Println("Cause:")
fmt.Println(err.Cause())
fmt.Println()
fmt.Println("Symptom:")
fmt.Println(err.Symptom())
}
}
handlerFunc()
// return as built-in Error, e.g. to AWS API GatewayextHandlerFunc:=func() error {
returnbusinessFunc()
}
_=extHandlerFunc()

About

Gracefully wrap and operate on errors.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages