You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.4 KiB
80 lines
1.4 KiB
package main
|
|
|
|
import (
|
|
"errs"
|
|
"errs/stack"
|
|
"fmt"
|
|
)
|
|
|
|
|
|
func printTrace (s stack.Trace) {
|
|
lf := s.Frames()
|
|
for i,f := range lf {
|
|
fmt.Printf("%d file %s line %d %s\n",i,f.File,f.LineNumber,f.FuncName)
|
|
}
|
|
}
|
|
|
|
|
|
type (
|
|
|
|
MiCustomErr struct {
|
|
error
|
|
ms string
|
|
}
|
|
)
|
|
|
|
func (c MiCustomErr) Message() string {
|
|
return "esto es un custom werro"
|
|
}
|
|
|
|
|
|
/*
|
|
func fm (b *bytes.Buffer, e error, l int) {
|
|
b.WriteString("Link :"+e.(MiCustomErr).Link+"\n")
|
|
}
|
|
*/
|
|
|
|
func (m MiCustomErr) Unwrap () error {
|
|
return m.error
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
ercode := errs.ErrCode("error->err-code")
|
|
//fmt.Print(errs.ToFormat(ercode,nil))
|
|
//fmt.Print("\n")
|
|
|
|
erpanic := errs.NewErrPanic(errs.PanicRecoveredError("error->err-mensaje-panico"))
|
|
fmt.Print(errs.ToFormat(erpanic,nil))
|
|
fmt.Print("\n")
|
|
|
|
panicInfo := erpanic.WrapWithInfo(errs.ErrInfoWithMessage("Un mensaje de panico"))
|
|
fmt.Print(errs.ToFormat(panicInfo,nil))
|
|
fmt.Print("\n")
|
|
|
|
ercause := ercode.WrapWithCause(errs.ErrCode("causa-2").WrapWithCause(errs.ErrCode("causa-1")))
|
|
fmt.Print(errs.ToFormat(ercause,nil))
|
|
fmt.Print("\n")
|
|
|
|
erInfo := errs.ErrCode("err-code-with-info").WrapWithInfo(errs.ErrInfoWithMessage("Esto es un mensaje"))
|
|
fmt.Print(errs.ToFormat(erInfo,nil))
|
|
fmt.Print("\n")
|
|
|
|
fmt.Print(string(errs.G.Formatter.Format(&MiCustomErr{error:errs.ErrCode("UnErrorCU") })))
|
|
fmt.Print("\n")
|
|
|
|
|
|
|
|
|
|
/*
|
|
ertrace := errs.ErrCode("err-code-with-trace").ToErrTrace(0)
|
|
fmt.Print(ertrace.String())
|
|
fmt.Print("\n")
|
|
*/
|
|
|
|
}
|