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.
136 lines
2.2 KiB
136 lines
2.2 KiB
package main
|
|
|
|
import (
|
|
"errs"
|
|
"errs/collects"
|
|
"errs/fjson"
|
|
"errs/ftext"
|
|
"errs/stack"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
|
|
func GenerateBinaryString() string {
|
|
binaryString := ""
|
|
for c := 0; c < 255; c++ {
|
|
if ('a' <= byte(c) && byte(c) <= 'z') || ('A' <= byte(c) && byte(c) <= 'Z') || byte(c) == '@' {
|
|
binaryString += "1"
|
|
} else {
|
|
binaryString += "0"
|
|
}
|
|
}
|
|
return binaryString
|
|
}
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
MiCustomErr struct {
|
|
error
|
|
ms string
|
|
}
|
|
)
|
|
|
|
func (c MiCustomErr) Message() string {
|
|
return "esto es un custom werro"
|
|
}
|
|
|
|
func (c MiCustomErr) Code() string {
|
|
return "custom-code"
|
|
}
|
|
|
|
func (c MiCustomErr) Int () int {
|
|
return 33423
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c MiCustomErr) Error () string {
|
|
return "ERRRROPROO"
|
|
}
|
|
|
|
func (c MiCustomErr) Unwrap () error {
|
|
return c.error
|
|
}
|
|
|
|
func (c MiCustomErr) Collect (collector collects.Collector) {
|
|
collector.AddFieldInt("UnInt",c.Int())
|
|
collector.AddFieldFloat("UnFloat",34.33)
|
|
collector.AddFieldAny("UnoCualquiera",struct {
|
|
A string
|
|
B int
|
|
T time.Time
|
|
F float64
|
|
}{
|
|
A : "UUnA",
|
|
B : 3,
|
|
T : time.Now(),
|
|
F : 2.343,
|
|
})
|
|
}
|
|
|
|
|
|
func printCollection (ec collects.ErrorCollection) {
|
|
if ec.Invalid != nil {
|
|
fmt.Printf("INvalid %s\n", ec.Invalid.Error())
|
|
}
|
|
ec.Fields.Sort()
|
|
|
|
fmt.Printf("Error: %s\n",ec.ErrStr)
|
|
fmt.Printf("Types: %d\n",len(ec.Types))
|
|
for _,t := range ec.Types {
|
|
fmt.Printf("\tWrap Type : %s\n",t.String())
|
|
}
|
|
fmt.Printf("Fields: \n")
|
|
for _,h := range ec.Fields.GetHeads() {
|
|
fmt.Printf("\t%s : %v\n",h.Name)
|
|
}
|
|
fmt.Printf("Causes: \n")
|
|
for _,c := range ec.Causes {
|
|
printCollection(c)
|
|
}
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
me := errs.WrapWithCause(errs.WrapWithInfo(MiCustomErr{},
|
|
errs.ErrInfoWithInfo("Mi mensaje")),errs.ErrCode("UnERRORito"))
|
|
|
|
|
|
mu := errs.NewErrMulti(
|
|
errs.ErrCode("UnError"),
|
|
errs.ErrCode("UnOtro"),
|
|
me,
|
|
)
|
|
|
|
|
|
|
|
|
|
//printCollection(*collr.NewErrorCollection(me).Collect(true,true,true))
|
|
|
|
|
|
f := ftext.DefaultFormatter()
|
|
j := fjson.DefaultFormatter()
|
|
|
|
fmt.Print(string(f.FormatError(errs.WrapWithTrace(mu,1))))
|
|
|
|
fmt.Print(string(j.FormatError(errs.WrapWithTrace(mu,1))))
|
|
|
|
}
|
|
|
|
|