Documentation ¶
Overview ¶
Package status is a handling status with code, msg, cause and stack.
Index ¶
- Constants
- func Catch(statPtr **Status, realStat ...*bool)
- func CatchWithStack(statPtr **Status, realStat ...*bool)
- func Check(err error, code int32, msg string, whenError ...func())
- func Panic(stat *Status)
- func Throw(code int32, msg string, cause ...interface{})
- func WrapError(cause interface{}, fields Map) error
- type Frame
- type Map
- type StackTrace
- type Status
- func (s *Status) Cause() error
- func (s *Status) Clear()
- func (s *Status) Code() int32
- func (s *Status) Copy(newCause interface{}, newStackSkip ...int) *Status
- func (s *Status) DecodeQuery(b []byte)
- func (s *Status) EncodeQuery() []byte
- func (s *Status) Format(state fmt.State, verb rune)
- func (s *Status) JSONString() string
- func (s *Status) MarshalJSON() ([]byte, error)
- func (s *Status) Msg() string
- func (s *Status) NewCheck(err error, whenError ...func())
- func (s *Status) NewThrow(cause ...interface{})
- func (s *Status) OK() bool
- func (s *Status) QueryString() string
- func (s *Status) SetCause(cause interface{}) *Status
- func (s *Status) SetCode(code int32) *Status
- func (s *Status) SetMsg(msg string) *Status
- func (s *Status) StackTrace() StackTrace
- func (s *Status) String() string
- func (s *Status) TagStack(skip ...int) *Status
- func (s *Status) UnknownError() bool
- func (s *Status) UnmarshalJSON(b []byte) error
Constants ¶
const ( // OK status OK int32 = 0 // UnknownError status UnknownError int32 = -1 )
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
Catch recovers the panic and returns status. NOTE:
Set `realStat` to true if a `Status` type is recovered
Example:
var stat *Status defer Catch(&stat)
func CatchWithStack ¶
CatchWithStack recovers the panic and returns status copy with stack. NOTE:
Set `realStat` to true if a `Status` type is recovered
Example:
var stat *Status defer CatchWithStack(&stat)
func Check ¶
Check if err!=nil, create a status with stack, and panic. NOTE:
If err!=nil and msg=="", error text is set to msg
Types ¶
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 ¶
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 ¶
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 StackTrace ¶
type StackTrace []Frame
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
func PanicStackTrace ¶
func PanicStackTrace() StackTrace
PanicStackTrace gets the panic stack trace.
func (StackTrace) Format ¶
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status a handling status with code, msg, cause and stack.
func NewWithStack ¶
NewWithStack creates a handling status with code, msg and cause and stack. NOTE:
code=0 means no error
func (*Status) Cause ¶
Cause returns the cause of the status for debugging (optional). NOTE:
If s.OK() is false, the return value is never nil; When empty, the msg is returned by default
func (*Status) DecodeQuery ¶
DecodeQuery parses the given b containing query args to the status object.
func (*Status) EncodeQuery ¶
EncodeQuery encodes the status object into query bytes.
func (*Status) Format ¶
Format formats the status object according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.
func (*Status) JSONString ¶
JSONString returns JSON string for the status object.
func (*Status) MarshalJSON ¶
MarshalJSON marshals the status object into JSON, implements json.Marshaler interface.
func (*Status) Msg ¶
Msg returns the status msg displayed to the user (optional). NOTE:
When empty, the reason is returned by default
func (*Status) NewThrow ¶
func (s *Status) NewThrow(cause ...interface{})
NewThrow copies the status with stack, and panic.
func (*Status) QueryString ¶
QueryString returns query string for the status object.
func (*Status) StackTrace ¶
func (s *Status) StackTrace() StackTrace
StackTrace returns stack trace.
func (*Status) UnknownError ¶
UnknownError returns whether is UnknownError status (code=-1).
func (*Status) UnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON description of self.