Documentation ¶
Index ¶
- Constants
- Variables
- func GetAWSErrorCode(err error) string
- func GetLogFields(err error) logrus.Fields
- func GetMergedLogFields(err error) logrus.Fields
- func GetRootError(err error) error
- func GetRuntimeContext() (fileName, funcName string, line int)
- func GetTrace() []string
- func ListToError(errs []error) error
- func LogDebug(err error)
- func LogDebugMerged(err error)
- func LogDebugPlain(err error)
- func LogError(err error)
- func LogErrorMerged(err error)
- func LogErrorPlain(err error)
- func LogInfo(err error)
- func LogInfoMerged(err error)
- func LogInfoPlain(err error)
- func LogWarning(err error)
- func LogWarningMerged(err error)
- func LogWarningPlain(err error)
- func LogWithSeverity(err error)
- func New(message string, fields ...Fields) error
- func NewWithSeverity(message string, fields Fields, severity LogSeverity) error
- func WithContext(err error, message string, fields ...Fields) error
- func WithContextAndSeverity(err error, message string, severity LogSeverity, fields ...Fields) error
- func Wrap(err error, message string, fields ...Fields) error
- type Cause
- type Fields
- type LogSeverity
- type NCError
- func (n NCError) As(target any) bool
- func (n NCError) Error() string
- func (n *NCError) GetContext() Fields
- func (n *NCError) GetMergedFields() Fields
- func (n *NCError) GetMergedFieldsContext() Fields
- func (n NCError) Is(target error) bool
- func (n NCError) StackTrace() errors.StackTrace
- func (n NCError) Unwrap() error
Constants ¶
const ( AWSAccessDenied = "AccessDenied" AWSAccessDeniedException = "AccessDeniedException" AWSDynamoTableNotFound = dynamodb.ErrCodeTableNotFoundException AWSS3BucketNotFound = s3.ErrCodeNoSuchBucket AWSRedshiftClusterSnapsotQuotaExceeded = redshift.ErrCodeClusterSnapshotQuotaExceededFault )
Variables ¶
A set of convenience wrappers for standard library 'errors' functions.
Functions ¶
func GetAWSErrorCode ¶
GetAWSErrorCode returns the underlying AWS error code from the error.
func GetLogFields ¶
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 ¶
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 GetRuntimeContext ¶
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 ¶
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 NewWithSeverity ¶
func NewWithSeverity(message string, fields Fields, severity LogSeverity) error
func WithContext ¶
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.
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.
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) GetContext ¶
GetContext returns fields from the error (with attached stack and causes fields) This will be used for logrus.WithFields method.
func (*NCError) GetMergedFields ¶
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 ¶
GetMergedFieldsContext returns error stack and merged fields.
func (NCError) Is ¶ added in v1.3.1
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.