errors

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: UNKNOWN, Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Types

type Error

type Error interface {
	Error() string
	Stacktrace() Error
	Trace(offset int, format string, args ...interface{}) Error
	Data() interface{}
}

Usage with arbitrary error data:

```go

// Error construction
type MyError struct{}
var err1 error = NewWithData(MyError{}, "my message")
...
// Wrapping
var err2 error  = Wrap(err1, "another message")
if (err1 != err2) { panic("should be the same")
...
// Error handling
switch err2.Data().(type){
	case MyError: ...
    default: ...
}

```

func New

func New(format string, args ...interface{}) Error

New Error with formatted message. The Error's Data will be a FmtError type.

func NewWithData

func NewWithData(data interface{}) Error

New Error with specified data.

func Wrap

func Wrap(cause interface{}, format string, args ...interface{}) Error

type FmtError

type FmtError struct {
	// contains filtered or unexported fields
}

FmtError is the data type for New() (e.g. New().Data().(FmtError)) Theoretically it could be used to switch on the format string.

```go

// Error construction
var err1 error = New("invalid username %v", "BOB")
var err2 error = New("another kind of error")
...
// Error handling
switch err1.Data().(cmn.FmtError).Format() {
	case "invalid username %v": ...
	case "another kind of error": ...
    default: ...
}

```

func (FmtError) Error

func (fe FmtError) Error() string

func (FmtError) Format

func (fe FmtError) Format() string

func (FmtError) String

func (fe FmtError) String() string

Jump to

Keyboard shortcuts

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