|
|
|
|
@ -96,21 +96,16 @@ func (o FormatShow) ShowDeepMetas() bool { return o&FormatShowDeepMetas != 0 }
|
|
|
|
|
func (o FormatShow) ShowStack() bool { return o&FormatShowStack != 0 }
|
|
|
|
|
func (o FormatShow) ShowDeepStacks() bool { return o&FormatShowDeepStacks != 0 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- Tipos de Error de Ejemplo para el Benchmark ---
|
|
|
|
|
|
|
|
|
|
type ErrorWithMessage struct {
|
|
|
|
|
error // Embebido para Unwrap y Error() si no se sobrescribe explícitamente msg
|
|
|
|
|
msg string
|
|
|
|
|
msg string
|
|
|
|
|
// wrapped error // Alternativa si no se quiere embeber 'error'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *ErrorWithMessage) Error() string
|
|
|
|
|
if e.msg != "" {
|
|
|
|
|
return e.msg
|
|
|
|
|
}
|
|
|
|
|
if e.error != nil {
|
|
|
|
|
return e.error.Error()
|
|
|
|
|
}
|
|
|
|
|
func (e *ErrorWithMessage) Error() string {
|
|
|
|
|
if e.msg != "" { return e.msg }
|
|
|
|
|
if e.error != nil { return e.error.Error() }
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
@ -122,18 +117,13 @@ func (e *ErrorWithMessage) Metadata(selector MetaSelector) []Meta {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
type ErrorWithSingleCause struct {
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
causeField error
|
|
|
|
|
g
|
|
|
|
|
}
|
|
|
|
|
if e.msg != "" {
|
|
|
|
|
return e.msg
|
|
|
|
|
}
|
|
|
|
|
if e.error != nil {
|
|
|
|
|
return e.error.Error()
|
|
|
|
|
}
|
|
|
|
|
func (e *ErrorWithSingleCause) Error() string {
|
|
|
|
|
if e.msg != "" { return e.msg }
|
|
|
|
|
if e.error != nil { return e.error.Error() }
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
@ -146,36 +136,27 @@ func (e *ErrorWithSingleCause) Metadata(selector MetaSelector) []Meta {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
type ErrorWithMultipleCauses struct {
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
causesField []error
|
|
|
|
|
|
|
|
|
|
func (e *ErrorWithMultipleCauses) Error() string {
|
|
|
|
|
if e.msg != "" {
|
|
|
|
|
return e.msg
|
|
|
|
|
}
|
|
|
|
|
if e.error != nil {
|
|
|
|
|
return e.error.Error()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (e *ErrorWithMultipleCauses) Error() string {
|
|
|
|
|
if e.msg != "" { return e.msg }
|
|
|
|
|
if e.error != nil { return e.error.Error() }
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
func (e *ErrorWithMultipleCauses) Causes() []error { return e.causesField }
|
|
|
|
|
func (e *ErrorWithMultipleCauses) Unwrap() error { return e.error }
|
|
|
|
|
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
|
|
|
|
|
type ErrorWithStack struct {
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
stackField []string
|
|
|
|
|
r
|
|
|
|
|
}
|
|
|
|
|
if e.msg != "" {
|
|
|
|
|
return e.msg
|
|
|
|
|
}
|
|
|
|
|
if e.error != nil {
|
|
|
|
|
return e.error.Error()
|
|
|
|
|
}
|
|
|
|
|
func (e *ErrorWithStack) Error() string {
|
|
|
|
|
if e.msg != "" { return e.msg }
|
|
|
|
|
if e.error != nil { return e.error.Error() }
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
@ -187,18 +168,13 @@ func (e *ErrorWithStack) Metadata(selector MetaSelector) []Meta {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
type ErrorWithGenericMeta struct {
|
|
|
|
|
error // Embebido
|
|
|
|
|
msg string
|
|
|
|
|
metasField []Meta
|
|
|
|
|
*
|
|
|
|
|
}
|
|
|
|
|
if e.msg != "" {
|
|
|
|
|
return e.msg
|
|
|
|
|
}
|
|
|
|
|
if e.error != nil {
|
|
|
|
|
return e.error.Error()
|
|
|
|
|
}
|
|
|
|
|
func (e *ErrorWithGenericMeta) Error() string {
|
|
|
|
|
if e.msg != "" { return e.msg }
|
|
|
|
|
if e.error != nil { return e.error.Error() }
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
@ -208,17 +184,11 @@ func (e *ErrorWithGenericMeta) Metadata(selector MetaSelector) []Meta {
|
|
|
|
|
for _, m := range e.metasField {
|
|
|
|
|
include := false
|
|
|
|
|
switch m.mType {
|
|
|
|
|
if selector.SelectStack() {
|
|
|
|
|
include = true
|
|
|
|
|
}
|
|
|
|
|
case MetaTypeStack:
|
|
|
|
|
if selector.SelectStack() { include = true }
|
|
|
|
|
if selector.SelectCause() {
|
|
|
|
|
include = true
|
|
|
|
|
}
|
|
|
|
|
case MetaTypeCause:
|
|
|
|
|
if selector.SelectCause() { include = true }
|
|
|
|
|
if selector.SelectValue() {
|
|
|
|
|
include = true
|
|
|
|
|
}
|
|
|
|
|
default: // MetaSelectValue
|
|
|
|
|
if selector.SelectValue() { include = true }
|
|
|
|
|
}
|
|
|
|
|
if include {
|
|
|
|
|
@ -228,6 +198,7 @@ func (e *ErrorWithGenericMeta) Metadata(selector MetaSelector) []Meta {
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- defaultFormatErrorOriginal (Tu versión) ---
|
|
|
|
|
func defaultFormatErrorOriginal(w io.Writer, err error, opts *FormatOptions, level int, show FormatShow) {
|
|
|
|
|
if err == nil {
|
|
|
|
|
@ -329,6 +300,7 @@ func defaultFormatErrorOriginal(w io.Writer, err error, opts *FormatOptions, lev
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- defaultFormatErrorRefactored (Mi versión) ---
|
|
|
|
|
func defaultFormatErrorRefactored(w io.Writer, currentErr error, opts *FormatOptions, level int, show FormatShow) {
|
|
|
|
|
if currentErr == nil {
|
|
|
|
|
@ -428,13 +400,14 @@ func defaultFormatErrorRefactored(w io.Writer, currentErr error, opts *FormatOpt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- Configuración del Benchmark ---
|
|
|
|
|
|
|
|
|
|
baseErr = TestErr("base error")
|
|
|
|
|
simpleErr = TestErr("simple error")
|
|
|
|
|
wrappedErr = &ErrorWithMessage{error: baseErr, msg: "L1 wrap"} // Unwrap chain
|
|
|
|
|
errWithMeta = &ErrorWithGenericMeta{error: baseErr, msg: "error with meta", metasField: []Meta{createMetaForBenchmark("key", "value", MetaTypeString)}}
|
|
|
|
|
errWithStack = &ErrorWithStack{error: baseErr, msg: "error with stack", stackField: []string{"frame1:10", "frame2:20"}}
|
|
|
|
|
var (
|
|
|
|
|
baseErr = TestErr("base error")
|
|
|
|
|
simpleErr = TestErr("simple error")
|
|
|
|
|
wrappedErr = &ErrorWithMessage{error: baseErr, msg: "L1 wrap"} // Unwrap chain
|
|
|
|
|
errWithMeta = &ErrorWithGenericMeta{error: baseErr, msg: "error with meta", metasField: []Meta{createMetaForBenchmark("key", "value", MetaTypeString)}}
|
|
|
|
|
errWithStack = &ErrorWithStack{error: baseErr, msg: "error with stack", stackField: []string{"frame1:10", "frame2:20"}}
|
|
|
|
|
errWithSingleCause = &ErrorWithSingleCause{error: baseErr, msg: "error with single cause", causeField: TestErr("the explicit cause")}
|
|
|
|
|
errWithMultiCause = &ErrorWithMultipleCauses{error: baseErr, msg: "error with multi cause", causesField: []error{TestErr("cause A"), TestErr("cause B")}}
|
|
|
|
|
@ -446,7 +419,7 @@ func defaultFormatErrorRefactored(w io.Writer, currentErr error, opts *FormatOpt
|
|
|
|
|
error: TestErr("complex base L5"),
|
|
|
|
|
msg: "complex L4 (meta)",
|
|
|
|
|
metasField: []Meta{createMetaForBenchmark("complex_key", 123, MetaTypeInt)},
|
|
|
|
|
msg: "complex L2 (single cause provider)",
|
|
|
|
|
},
|
|
|
|
|
msg: "complex L2 (single cause provider)",
|
|
|
|
|
causeField: &ErrorWithMessage{msg: "explicit complex cause L3 (message)"}, // Esta es la causa explícita
|
|
|
|
|
}
|
|
|
|
|
|