errors

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AWSAccessDenied          = "AccessDenied"
	AWSAccessDeniedException = "AccessDeniedException"

	AWSDynamoTableNotFound = dynamodb.ErrCodeTableNotFoundException
	AWSS3BucketNotFound    = s3.ErrCodeNoSuchBucket

	AWSRedshiftClusterSnapsotQuotaExceeded = redshift.ErrCodeClusterSnapshotQuotaExceededFault
)

Variables

View Source
var (
	Unwrap = errors.Unwrap
	Is     = errors.Is
	As     = errors.As
)

A set of convenience wrappers for standard library 'errors' functions.

Functions

func GetAWSErrorCode

func GetAWSErrorCode(err error) string

GetAWSErrorCode returns the underlying AWS error code from the error.

func GetLogFields

func GetLogFields(err error) logrus.Fields

GetLogFields converts an error into `logrus.Fields`. It will set an `error` field so you don't have to use the `WithError()` method on your own. Additionally it will also fill the output with an error context under the `error context` field.

func GetMergedLogFields

func GetMergedLogFields(err error) logrus.Fields

GetLogFields converts an error into `logrus.Fields`. It will set an `error` field so you don't have to use the `WithError()` method on your own. Additionally it will also fill the output with an error context with merged causes' fields under the `error context` field.

func GetRootError

func GetRootError(err error) error

GetRootError returns root error.

func GetRuntimeContext

func GetRuntimeContext() (fileName, funcName string, line int)

GetRuntimeContext returns function name and code line.

func GetTrace

func GetTrace() []string

GetTrace return the simplified stack trace in the format file_name(func_name):line. It also contains the current goroutine entrypoint.

func ListToError

func ListToError(errs []error) error

ListToError converts errors list to single error

func LogDebug

func LogDebug(err error)

LogDebug logs err at level = debug. (uses a newly created `logrus.Entry`)

func LogDebugMerged

func LogDebugMerged(err error)

LogDebugMerged logs err at level = debug. and merged fields as context. (uses a newly created `logrus.Entry`)

func LogDebugPlain

func LogDebugPlain(err error)

LogDebugPlain logs error with its merged fields and stack at level = Debug.

func LogError

func LogError(err error)

LogError logs err with `logrus.Error` method (level=error). (uses a newly created `logrus.Entry`)

func LogErrorMerged

func LogErrorMerged(err error)

LogErrorMerged logs err with `logrus.Error` method (level=error) and merged fields as context. (uses a newly created `logrus.Entry`)

func LogErrorPlain

func LogErrorPlain(err error)

LogErrorPlain logs error with its merged fields and stack at level = Error.

func LogInfo

func LogInfo(err error)

LogInfo logs err at level = info. (uses a newly created `logrus.Entry`)

func LogInfoMerged

func LogInfoMerged(err error)

LogInfoMerged logs err at level = info. and merged fields as context. (uses a newly created `logrus.Entry`)

func LogInfoPlain

func LogInfoPlain(err error)

LogInfoPlain logs error with its merged fields and stack at level = Info.

func LogWarning

func LogWarning(err error)

LogWarning logs err at level = warning. (uses a newly created `logrus.Entry`)

func LogWarningMerged

func LogWarningMerged(err error)

LogWarningMerged logs err at level = warning. and merged fields as context. (uses a newly created `logrus.Entry`)

func LogWarningPlain

func LogWarningPlain(err error)

LogWarningPlain logs error with its merged fields and stack at level = Warning.

func LogWithSeverity

func LogWithSeverity(err error)

LogWithSeverity uses severity stored in the error to select appropriate log level.

func New

func New(message string, fields ...Fields) error

New error with context.

func NewWithSeverity

func NewWithSeverity(message string, fields Fields, severity LogSeverity) error

func WithContext

func WithContext(err error, message string, fields ...Fields) error

WithContext set new error wrapped with message and error context.

func WithContextAndSeverity

func WithContextAndSeverity(err error, message string, severity LogSeverity, fields ...Fields) error

WithContextAndSeverity set new error wrapped with message, severity and error context.

func Wrap added in v1.2.0

func Wrap(err error, message string, fields ...Fields) error

Wrap wraps WithContext and checks for nil error.

Types

type Cause

type Cause struct {
	Message  string
	Fields   Fields
	FuncName string
	FileName string
	Line     int
	Severity LogSeverity
}

Cause keeps the context information about the error.

type Fields

type Fields map[string]interface{}

Fields keeps context.

func (Fields) Add added in v1.2.0

func (f Fields) Add(key string, val interface{}) Fields

Add adds key:val to the Fields, returns fresh extended copy. The original Fields remains intact.

func (Fields) Extend added in v1.2.0

func (f Fields) Extend(extFields Fields) Fields

Extend extends Fields with the content of extFields, returns fresh extended copy. The original Fields remains intact.

type LogSeverity

type LogSeverity string
const (
	//ERROR Severity - logged with error level
	ERROR LogSeverity = "error"
	//WARN Severity warn - logged with warning level
	WARN LogSeverity = "warning"
	//INFO Severity - logged with info level
	INFO LogSeverity = "info"
	//DEBUG Severity - logged with Debug level
	DEBUG LogSeverity = "debug"
)

func GetErrorSeverity

func GetErrorSeverity(err error) LogSeverity

GetErrorSeverity returns outermost NCError severity or ERROR level.

type NCError

type NCError struct {
	// NOT DOCUMENTED BY ORIGINAL CREATOR. Stores root error and wrapped NCError errors. No information is provided why
	// such non-standard design was chosen - might be to reduce stacktrace duplication.
	Causes []Cause
	// Contains stack trace from the initial place when the error
	// was raised.
	Stack []string
	// Raw stack trace in the form of program counters, as returned by the runtime.Callers
	RawStack *stack
	//The root error at the base level.
	RootError error
}

NCError basic error structure.

func (NCError) As added in v1.3.1

func (n NCError) As(target any) bool

As checks if given error type is equal.

func (NCError) Error

func (n NCError) Error() string

func (*NCError) GetContext

func (n *NCError) GetContext() Fields

GetContext returns fields from the error (with attached stack and causes fields) This will be used for logrus.WithFields method.

func (*NCError) GetMergedFields

func (n *NCError) GetMergedFields() Fields

GetMergedFields returns fields from the error. The custom fields are merged from every error's cause's fields (as defined by WithContext invocations). If the field with the same name is present in multiple causes the value from the outermost cause is taken. This will be used for logrus.WithFields method.

func (*NCError) GetMergedFieldsContext

func (n *NCError) GetMergedFieldsContext() Fields

GetMergedFieldsContext returns error stack and merged fields.

func (NCError) Is added in v1.3.1

func (n NCError) Is(target error) bool

Is checks if given error is equal. Solution is quite weird due to awkward wrap design.

func (NCError) StackTrace added in v1.3.0

func (n NCError) StackTrace() errors.StackTrace

StackTrace returns github.com/pkg/errors stack trace. This is to implement interface from aws-xray-sdk-go for passing along stack traces to X-Ray to segments.

func (NCError) Unwrap added in v1.1.0

func (n NCError) Unwrap() error

Unwrap returns underlying non-NCError error. If no errors were wrapped by NCError then returns nil.

Jump to

Keyboard shortcuts

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