123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package fserr
- import (
- "fmt"
- "io"
- )
- type fundamental struct {
- msg string
- *stack
- }
- func (f *fundamental) Error() string { return f.msg }
- func (f *fundamental) Format(s fmt.State, verb rune) {
- switch verb {
- case 'v':
- if s.Flag('+') {
- io.WriteString(s, f.msg)
- f.stack.Format(s, verb)
- return
- }
- fallthrough
- case 's':
- io.WriteString(s, f.msg)
- case 'q':
- fmt.Fprintf(s, "%q", f.msg)
- }
- }
- type withStack struct {
- error
- *stack
- }
- func (w *withStack) Cause() error { return w.error }
- func (w *withStack) Unwrap() error { return w.error }
- func (w *withStack) Format(s fmt.State, verb rune) {
- switch verb {
- case 'v':
- if s.Flag('+') {
- if w.Cause() != nil {
- fmt.Fprintf(s, "%+v", w.Cause())
- }
- w.stack.Format(s, verb)
- return
- }
- fallthrough
- case 's':
- io.WriteString(s, w.Error())
- case 'q':
- fmt.Fprintf(s, "%q", w.Error())
- }
- }
- type withMessage struct {
- cause error
- msg string
- }
- func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
- func (w *withMessage) Cause() error { return w.cause }
- func (w *withMessage) Unwrap() error { return w.cause }
- func (w *withMessage) Format(s fmt.State, verb rune) {
- switch verb {
- case 'v':
- if s.Flag('+') {
- io.WriteString(s, w.msg+": ")
- if w.Cause() != nil {
- fmt.Fprintf(s, "%+v", w.Cause())
- }
- return
- }
- fallthrough
- case 's':
- io.WriteString(s, w.Error())
- case 'q':
- fmt.Fprintf(s, "%q", w.Error())
- }
- }
- type withCode struct {
- cause error
- Msg string `json:"msg"`
- HttpCode int `json:"httpCode"`
- BusinessCode int `json:"businessCode"`
- }
- func (w *withCode) Error() string { return w.Msg }
- func (w *withCode) Cause() error { return w.cause }
- func (w *withCode) Unwrap() error { return w.cause }
- func (w *withCode) Format(s fmt.State, verb rune) {
- switch verb {
- case 'v':
- if s.Flag('+') {
- io.WriteString(s, w.Msg+"\n")
- if w.Cause() != nil {
- fmt.Fprintf(s, "%+v", w.Cause())
- }
- return
- }
- fallthrough
- case 's':
- io.WriteString(s, w.Error())
- case 'q':
- fmt.Fprintf(s, "%q", w.Error())
- }
- }
|