terminando de crear el formateador de texto de errores

master
DEV 3 years ago
parent 39cbf7a138
commit ecd6c7c1d5

@ -4,7 +4,6 @@ import (
"bytes"
"errs"
"fmt"
"reflect"
)
@ -58,10 +57,4 @@ func main() {
fmt.Print(string(errs.G.Formatter.Format(eM)))
for i,e := range errs.UnwrapAll(eM) {
fmt.Printf("%d type: %s errror : %v\n", i,reflect.TypeOf(e),e)
}
}

@ -39,6 +39,9 @@ const (
)
var (
G = struct {
@ -155,3 +158,4 @@ func UnwrapStackTrace(err error) StackTracer {
return nil
}

@ -0,0 +1,47 @@
// ------------------------------------------------------------------------
// Project active2
// Active Thing (activething.com) git.activething.com/go
//
// File name color.go
// Created by DEV
// Modified 27/03/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package errs
import "fmt"
const (
ColorBlack TextColor = iota + 30
ColorRed
ColorGreen
ColorYellow
ColorBlue
ColorMagenta
ColorCyan
ColorWhite
)
type (
TextColor uint8
)
func (c TextColor) Sprint (fm string, params ...any) string {
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", uint8(c),fmt.Sprintf(fm,params...)) }

@ -30,6 +30,10 @@ import (
"time"
)
type (
FmtText struct {
@ -47,7 +51,7 @@ type (
func NewFmtText(options ...FmtTextFnc) *FmtText {
return applyFmtTextOptions(&FmtText{
FmtTextAtt: FmtTextAttIndent | FmtTextAttVerbose,
FmtTextAtt: FmtTextAttIndent | FmtTextAttVerbose | FmtTextAttTrace,
indent : " ",
traceFmt : formatStackTrace ,
}, options...) }
@ -210,8 +214,21 @@ func formatErrAny (s *FmtTextState, err error) {
func formatStackTrace(s *FmtTextState, t StackTrace) {
for _,f := range t.Frames() {
sl,_ := f.SourceLine()
s.WriteFieldString(f.FuncName,sl)
s.Buffer.WriteString(f.Package)
s.Buffer.WriteByte(':')
s.Buffer.WriteString(f.FuncName)
s.Buffer.WriteByte('\n')
s.Buffer.WriteByte('\t')
s.Buffer.WriteString(f.File)
s.Buffer.WriteByte(':')
s.Buffer.WriteString(fmt.Sprintf("%d\n",f.LineNumber))
if sc,er := f.SourceLine(); er == nil {
s.Buffer.WriteString(ColorMagenta.Sprint(sc))
//s.Buffer.WriteString(fmt.Sprintf("\t\x1b[%dm%s\x1b[0m\b\n", uint8(Green), sc))
//s.Buffer.WriteByte('\t')
//s.Buffer.WriteString(sc)
//s.Buffer.WriteByte('\n')
}
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.