common

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 = NewErrorWithData(MyError{}, "my message")
...
// Wrapping
var err2 error  = ErrorWrap(err1, "another message")
if (err1 != err2) { panic("should be the same")
...
// Error handling
switch err2.Data().(type){
	case MyError: ...
    default: ...
}

```

func ErrorWrap

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

func NewError

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

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

func NewErrorWithData

func NewErrorWithData(data interface{}) Error

New Error with specified data.

type FmtError

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

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

```go

// Error construction
var err1 error = NewError("invalid username %v", "BOB")
var err2 error = NewError("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