errors

package module
v1.1.19 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 7 Imported by: 23

README

errors

Documentation

Overview

Example (ErrorsUsage)
package main

import (
	"fmt"

	"git.corout.in/golibs/fields"
	"git.corout.in/golibs/slog"
	"git.corout.in/golibs/slog/zaplogger"

	"git.corout.in/golibs/errors"
)

func main() {
	err := fmt.Errorf("Some error")

	err = errors.Ctx().
		Int("test-int-key", 10).
		Str("test-str-key", "blah-blah").
		Just(err)

	log := zaplogger.New(slog.DebugLevel, true)

	log.Error("Test error", err)
	log.Errorf("Test error with arg: %s", "test arg", err)
	log.Error(
		"Test error with additional fields",
		fields.Str("additional", "field"),
		fields.Bool("is_worked", true),
		err,
	)

	err = errors.Wrap(err, "test wrap wrapped error")
	log.Error("Have new wrapped error", err)

	err = errors.Ctx().Str("injecting", "this some injecting on next level").Just(err)
	log.Error("Next level injected fields", err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And(err1, err2 error) error

And собирает ошибки в цепочку

func As

func As(err error, target interface{}) bool

func Extract

func Extract(err error) []fields.Field

func Formatted added in v1.1.0

func Formatted(err error, args ...interface{}) error

Formatted конструктор форматированной аннотированной полями ошибки

func Is

func Is(err, target error) bool

func New

func New(reason string) error

func RecoverError added in v1.1.0

func RecoverError(reason interface{}) error

func Wrap

func Wrap(err error, message string) error

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Types

type Chain

type Chain []error

Chain - цепочка ошибок

func AsChain

func AsChain(err error) Chain

AsChain ищет тип `errors.Chain` во вложенных ошибках и возвращает его. Если цепочки не найдено, то создаётся новая, состоящая из текущей ошибки.

func (Chain) As

func (ch Chain) As(target interface{}) bool

func (Chain) Error

func (ch Chain) Error() string

func (Chain) Is

func (ch Chain) Is(err error) bool

type Const

type Const string

Const - тип используемый для константных ошибок, позволяет избегать возможных мутаций значений ошибок.

func (Const) Error

func (e Const) Error() string

type ContextError added in v1.1.0

type ContextError interface {
	Just(err error) error
	New(reason string) error
	Newf(format string, args ...interface{}) error
	Wrap(err error, reason string) error
	Wrapf(err error, format string, args ...interface{}) error
	With(flds ...fields.Field) ContextError
	Pos(depth int) ContextError

	Bool(key string, value bool) ContextError
	Int(key string, value int) ContextError
	Int8(key string, value int8) ContextError
	Int16(key string, value int16) ContextError
	Int32(key string, value int32) ContextError
	Int64(key string, value int64) ContextError
	Uint(key string, value uint) ContextError
	Uint8(key string, value uint8) ContextError
	Uint16(key string, value uint16) ContextError
	Uint32(key string, value uint32) ContextError
	Uint64(key string, value uint64) ContextError
	Float32(key string, value float32) ContextError
	Float64(key string, value float64) ContextError
	Str(key string, value string) ContextError
	Strings(key string, values []string) ContextError
	Stringer(key string, value fmt.Stringer) ContextError
	Any(key string, value interface{}) ContextError
	WithStack() ContextError
	Extract(out fields.FieldExtractor)
}

ContextError - интерфейс контекстной (анотированной полями) ошибки

func Ctx added in v1.1.0

func Ctx() ContextError

Ctx - конструтор контекстной ошибки для определния полей в блоках условий для последующей обертки или формирования как есть

type ErrRecover added in v1.1.0

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

func (ErrRecover) Error added in v1.1.0

func (e ErrRecover) Error() string

type FormattedError added in v1.1.0

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

FormattedError форматированная ошибка для вывода в результатах тестов

func (*FormattedError) Any added in v1.1.0

func (f *FormattedError) Any(key string, value interface{})

func (*FormattedError) Bool added in v1.1.0

func (f *FormattedError) Bool(key string, value bool)

func (*FormattedError) Error added in v1.1.0

func (f *FormattedError) Error() string

func (*FormattedError) Float32 added in v1.1.0

func (f *FormattedError) Float32(key string, value float32)

func (*FormattedError) Float64 added in v1.1.0

func (f *FormattedError) Float64(key string, value float64)

func (*FormattedError) Int added in v1.1.0

func (f *FormattedError) Int(key string, value int)

func (*FormattedError) Int16 added in v1.1.0

func (f *FormattedError) Int16(key string, value int16)

func (*FormattedError) Int32 added in v1.1.0

func (f *FormattedError) Int32(key string, value int32)

func (*FormattedError) Int64 added in v1.1.0

func (f *FormattedError) Int64(key string, value int64)

func (*FormattedError) Int8 added in v1.1.0

func (f *FormattedError) Int8(key string, value int8)

func (*FormattedError) Str added in v1.1.0

func (f *FormattedError) Str(key, value string)

func (*FormattedError) Strings added in v1.1.0

func (f *FormattedError) Strings(key string, values []string)

func (*FormattedError) Uint added in v1.1.0

func (f *FormattedError) Uint(key string, value uint)

func (*FormattedError) Uint16 added in v1.1.0

func (f *FormattedError) Uint16(key string, value uint16)

func (*FormattedError) Uint32 added in v1.1.0

func (f *FormattedError) Uint32(key string, value uint32)

func (*FormattedError) Uint64 added in v1.1.0

func (f *FormattedError) Uint64(key string, value uint64)

func (*FormattedError) Uint8 added in v1.1.0

func (f *FormattedError) Uint8(key string, value uint8)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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