agerrors

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the root cause error of `err`.

func Code

func Code(err error) agcodes.Coder

func Current

func Current(err error) error

Current creates and returns the current level error. It returns nil if current level error is nil.

func Equal

func Equal(err, target error) bool

Equal reports whether current error `err` equals to error `target`. Please note that, in default comparison logic for `Error`, the errors are considered the same if both the `code` and `text` of them are the same.

func HasCode

func HasCode(err error, code agcodes.Coder) bool

HasCode checks and reports whether `err` has `code` in its chaining errors.

func HasError

func HasError(err, target error) bool

HasError is alias of Is, which more easily understanding semantics.

func HasStack

func HasStack(err error) bool

HasStack checks and reports whether `err` implemented interface `gerror.IStack`.

func Is

func Is(err, target error) bool

Is reports whether current error `err` has error `target` in its chaining errors. It is just for implements for stdlib errors.Is from Go version 1.17.

func New

func New(s string) error

New creates and returns an error which is formatted from given text.

func NewCode

func NewCode(code agcodes.Coder, s ...string) error

NewCode creates and returns an error that has error code and given text.

Example
package main

import (
	"fmt"
	"github.com/wond4/go-frame/core/errorx/agcodes"
	"github.com/wond4/go-frame/core/errorx/agerrors"
)

func main() {

	err := agerrors.NewCode(
		//agcodes.New("10000", "", "", "", nil, ""),
		agcodes.CodeInvalidParameter,
		"My Error")

	fmt.Println(err.Error())
	fmt.Println(agerrors.Code(err))
}
Output:
My Error
Public.InvalidParameter:调用服务 [serviceName] 接口 [interfaceName] 参数值 [params] 校验不通过。

func NewCodeF

func NewCodeF(code agcodes.Coder, format string, a ...interface{}) error

NewCodeF returns an error that has error code and formats as the given format and args.

func NewF

func NewF(format string, a ...interface{}) error

New creates and returns an error that formats as the given format and args.

func Stack

func Stack(err error) string

Stack returns the stack callers as string. It returns the error string directly if the `err` does not support stacks.

func Unwrap

func Unwrap(err error) error

Unwrap returns the next level error. It returns nil if current level error or the next level error is nil.

func Wrap

func Wrap(e error, s string) error

Wrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier.

Types

type Error

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

Error is custom error for additional features.

func (*Error) Cause

func (err *Error) Cause() error

Cause returns the root cause error.

func (*Error) Code

func (err *Error) Code() agcodes.Coder

Code returns the error code. It returns CodeNil if it has no error code.

func (*Error) Current

func (err *Error) Current() error

Current creates and returns the current level error. It returns nil if current level error is nil.

func (*Error) Equal

func (err *Error) Equal(target error) bool

Equal reports whether current error `err` equals to error `target`. Please note that, in default comparison for `Error`, the errors are considered the same if both the `code` and `text` of them are the same.

func (*Error) Error

func (err *Error) Error() string

Error implements the interface of Error, it returns all the error as string.

func (*Error) Is

func (err *Error) Is(target error) bool

Is reports whether current error `err` has error `target` in its chaining errors. It is just for implements for stdlib errors.Is from Go version 1.17.

func (*Error) SetCode

func (err *Error) SetCode(code agcodes.Coder)

SetCode updates the internal code with given code.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap is alias of function `Next`. It is just for implements for stdlib errors.Unwrap from Go version 1.17.

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type ICause

type ICause interface {
	Error() string
	Cause() error
}

ICause is the interface for Cause feature.

type ICode

type ICode interface {
	Error() string
	Code() agcodes.Coder
}

type ICurrent

type ICurrent interface {
	Error() string
	Current() error
}

ICurrent is the interface for Current feature.

type IEqual

type IEqual interface {
	Error() string
	Equal(target error) bool
}

IEqual is the interface for Equal feature.

type IIs

type IIs interface {
	Error() string
	Is(target error) bool
}

IIs is the interface for Is feature.

type IStack

type IStack interface {
	Error() string
	Stack() string
}

IStack is the interface for Stack feature.

type IUnwrap

type IUnwrap interface {
	Error() string
	Unwrap() error
}

IUnwrap is the interface for Unwrap feature.

Jump to

Keyboard shortcuts

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