failure

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 2 Imported by: 27

README

Failure

The failure package builds upon the errors package, implementing a strategy called Opaque errors which I first learned about from an article [Don't just check errors handle the gracefully] (https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully) by Dave Cheney who I believe is also the author of the errors package.

Failure is geared towards describing errors that occur while using microservices that generally support rest api's and as such you will notice a slight bias towards that, although I try to separate concerns as much as possible. It is heavily influenced by sls a library used to develop AWS Serverless applications using Golang and Terraform.

Documentation

Overview

Package failure implements an opaque error pattern based several of the most common types of errors that occur when developing microservices.

Index

Constants

View Source
const (
	SystemMsg     = "system failure"
	PlatformMsg   = "platform failure"
	ServerMsg     = "server failure"
	NotFoundMsg   = "not found failure"
	ValidationMsg = "validation failure"
	IgnoreMsg     = "ignore failure"
)

Variables

This section is empty.

Functions

func Ignore

func Ignore(format string, a ...interface{}) error

Ignore is used to signify that error should not be acted on, it's up to the handler to decide to log these errors or not.

func Input

func Input(internalErr error, format string, a ...interface{}) error

func InputMsg

func InputMsg(e error) (string, bool)

func IsIgnore

func IsIgnore(err error) bool

func IsInput

func IsInput(e error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsPlatform

func IsPlatform(err error) bool

IsPlatform will return true if the cause is a platErr

func IsServer

func IsServer(err error) bool

IsServer will return true if the cause is a serverErr

func IsSystem

func IsSystem(err error) bool

IsSystem will return true if the cause is a serverErr

func IsValidation

func IsValidation(err error) bool

func NotFound

func NotFound(format string, a ...interface{}) error

NotFound is used to signify that whatever resource you were looking for does not exist and that fact it does not exist is an error.

func Platform

func Platform(format string, a ...interface{}) error

Platform failure is intended to represent low level errors that originate at the most concrete part of your architecture. I typically name this layer as platform hence the error type. It has the same meaning as Server or System. The idea is you choose the name that reads the best for your code and stay with that one. It is not recommended mixing these.

func Server

func Server(format string, a ...interface{}) error

Server has the same meaning as Platform or System, it can be used instead if you don't like how Platform or System reads in your code.

func System

func System(format string, a ...interface{}) error

System is has the same meaning as Platform or Server, it can be used instead if you don't like how Platform reads in your code

func ToIgnore

func ToIgnore(e error, format string, a ...interface{}) error

ToIgnore converts `e` into the root cause of ignoreErr, it informs the system to ignore this outside error.

func ToNotFound

func ToNotFound(e error, format string, a ...interface{}) error

ToNotFound converts `e` into the root cause of errNotFound

func ToPlatform

func ToPlatform(e error, format string, a ...interface{}) error

ToPlatform will convert err to the root cause as a Platform type. This is used when the `Platform Layer` of your code any library other than your own, and you want that error to be the root cause as type Platform. This will preserve the original message, just moving it into the new type.

func ToServer

func ToServer(e error, format string, a ...interface{}) error

ToServer behaves in the same manner as any ToXX function. Making err the root cause of type systemErr in our wrap.

func ToSystem

func ToSystem(e error, format string, a ...interface{}) error

ToSystem behaves in the same manner as any ToXX function. Making err the root cause of type systemErr in our wrap.

func ToValidation

func ToValidation(e error, format string, a ...interface{}) error

ToValidation converts `e` into the root cause of errNotFound

func Validation

func Validation(format string, a ...interface{}) error

Validation is used to signify that a validation rule as been violated

func Wrap

func Wrap(err error, msg string, a ...interface{}) error

Wrap expose errors.Wrapf as our default wrapping style

Types

This section is empty.

Jump to

Keyboard shortcuts

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