...

Package errors

import "edge-infra.dev/pkg/lib/errors"
Overview
Index

Overview ▾

Package errors provides common custom Error types.

type ContextualError

ContextualError is a custom error that can wrap an existing error and provides additional context based on the function that created the error, if created via New()

type ContextualError struct {
    Err     error
    Context string
    Message string
}

func New

func New(msg string, e error) *ContextualError

New creates a ContextualError using the provided message and wrapped Error. It also attempts to determine additional context automatically based on the file + function that is calling New(). If the context cannot be determined, it gracefully degrades into a regular wrapped Error.

Error context is in the form:

$package:$file#$line

edge-infra.dev/pkg/lib/errors.TestContextualError:pkg/errors/contextual_errors_test.go#12

func Wrap

func Wrap(e error) *ContextualError

Wrap creates a ContextualError without a message

func (*ContextualError) Error

func (c *ContextualError) Error() string

Error builds the error string based on the ContextualError state

func (*ContextualError) Unwrap

func (c *ContextualError) Unwrap() error