parent
70814fe835
commit
0d0e220350
@ -0,0 +1,41 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name causer.go
|
||||
// Created by DEV
|
||||
// Modified 20/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
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
Causers interface {
|
||||
|
||||
Causes () []error
|
||||
}
|
||||
|
||||
CausesFnc func () []error
|
||||
)
|
||||
|
||||
|
||||
func (f CausesFnc) Causes() []error {
|
||||
return f() }
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name builder_fallback.go
|
||||
// Created by DEV
|
||||
// Modified 13/04/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 err_fmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
|
||||
BuilderErrorFallback func (err error) string
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
func MakeErrorFallback (message string) BuilderErrorFallback {
|
||||
return func(err error) string {
|
||||
return fmt.Sprintf(message,err,reflect.TypeOf(err).String())
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name active.go
|
||||
// Created by DEV
|
||||
// Modified 12/04/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 fmx
|
||||
|
||||
import (
|
||||
"ansi"
|
||||
"errs/err_fmt"
|
||||
"errs/stack"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
fbBuildError string = "Error building error format for type '%v'. Check formatter configuration or consider handling unsupported error types gracefully. Error: %s"
|
||||
fbUnwrapError string = "Error building error from wrapped error. Encountered type '%v'. Consider handling this type explicitly or providing a generic fallback message. Error: %s"
|
||||
fbCauseError string = "Error formatting cause error. Encountered type '%v'. Review formatter logic for handling cause errors or provide a generic fallback message. Error: %s"
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
func defaultFrameBuilder(builder err_fmt.Builder, frame stack.Frame, num int) {
|
||||
if strings.Index(frame.Package,"runtime") != -1 {
|
||||
return
|
||||
}
|
||||
var c1, c2, c3, c4 ansi.Code
|
||||
/*
|
||||
if builder.Options().ShowAnsi(){
|
||||
c1 = c1.SetFgColor(ansi.ColorBlue).SetBgColor(ansi.ColorHWhite)
|
||||
c2 = c2.SetFgColor(ansi.ColorMagenta)
|
||||
c3 = c3.SetFgColor(ansi.ColorWhite)
|
||||
c4 = c3.SetStyle(ansi.StyleBold).SetFgColor(ansi.ColorHWhite)
|
||||
}
|
||||
|
||||
*/
|
||||
nm := c4.Sprintf(" %d ",num)
|
||||
ln := c1.Sprintf(fmt.Sprintf("%-60s",fmt.Sprintf(" %s.%s", frame.Package, frame.FuncName)))
|
||||
builder.AddText(fmt.Sprint(nm,ln))
|
||||
builder.AddText(c2.Sprintf(" %.90s:%d", frame.File, frame.LineNumber))
|
||||
f, e := frame.SourceLine()
|
||||
if e == nil {
|
||||
builder.AddText(c3.Sprintf(" %s\n", f))
|
||||
} else {
|
||||
//builder.AddText(c3.Sprintf(" error %s\n", e.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name field_format.go
|
||||
// Created by DEV
|
||||
// Modified 04/04/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 fmx
|
||||
|
||||
import (
|
||||
"ansi"
|
||||
"atypes/astrings"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
fieldFormat struct {
|
||||
NameAnsi ansi.Code
|
||||
ValueAnsi ansi.Code
|
||||
NameTrans astrings.Transformers
|
||||
ValueTrans astrings.Transformers
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func (f fieldFormat) clone() fieldFormat {
|
||||
return fieldFormat{
|
||||
NameAnsi: f.NameAnsi,
|
||||
ValueAnsi: f.ValueAnsi,
|
||||
NameTrans: append(astrings.Transformers(nil),f.NameTrans...),
|
||||
ValueTrans: append(astrings.Transformers(nil),f.ValueTrans...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,87 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name fmt_ops.go
|
||||
// Created by DEV
|
||||
// Modified 13/04/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 fmx
|
||||
|
||||
func WithLayout (name, layout string) TextFmtFnc {
|
||||
return func(f *TextFmt) {
|
||||
switch name {
|
||||
case "time":
|
||||
f.vLayouts.timeLayout = layout
|
||||
case "date":
|
||||
f.vLayouts.dateLayout = layout
|
||||
case "int":
|
||||
f.vLayouts.intLayout = layout
|
||||
case "float":
|
||||
f.vLayouts.floatLayout = layout
|
||||
case "bool":
|
||||
f.vLayouts.boolLayout = layout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func WithShowOptions (option erfmt.BuilderOption,enabled bool) FmtTextFnc {
|
||||
return func(f *ErrTextFormatter) {
|
||||
if enabled {
|
||||
f.options |= option
|
||||
return
|
||||
}
|
||||
f.options &^=option
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func WithSectionFormat(id int, config func (s *SectionFormat)) FmtTextFnc {
|
||||
if id < DefaultSection && id > TraceSection {
|
||||
return func(_ *ErrTextFormatter){}
|
||||
}
|
||||
return func(f *ErrTextFormatter) {
|
||||
config(&f.secs[id])
|
||||
}
|
||||
}
|
||||
|
||||
func WithFieldFormat(field string, config func(format *FieldFormat)) FmtTextFnc {
|
||||
return func(f *ErrTextFormatter) {
|
||||
if field == "" || field == "*" {
|
||||
config(&f.defFieldFormat)
|
||||
return
|
||||
}
|
||||
if f.fieldsFormat == nil {
|
||||
f.fieldsFormat = make(map[string]FieldFormat)
|
||||
}
|
||||
fm := FieldFormat{}
|
||||
config(&fm)
|
||||
if strings.Index(field,",") == -1 {
|
||||
f.fieldsFormat[field]=fm
|
||||
return
|
||||
}
|
||||
for _,fn := range strings.SplitAfter(field,",") {
|
||||
f.fieldsFormat[fn]=fm
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
@ -0,0 +1,55 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name layouts.go
|
||||
// Created by DEV
|
||||
// Modified 13/04/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 fmx
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
layouts struct {
|
||||
sep string
|
||||
indent string
|
||||
timeLayout string
|
||||
dateLayout string
|
||||
intLayout string
|
||||
floatLayout string
|
||||
boolLayout string
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
func newLayouts () *layouts {
|
||||
return &layouts{
|
||||
indent : " ",
|
||||
sep : " : ",
|
||||
timeLayout : time.RFC822Z,
|
||||
dateLayout : time.RFC822Z,
|
||||
intLayout : "%d",
|
||||
floatLayout : "%-10s: %.2f",
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name state_builder.go
|
||||
// Created by DEV
|
||||
// Modified 12/04/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 fmx
|
||||
|
||||
import (
|
||||
"errs/err_fmt"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *state) AddText(str string) {}
|
||||
|
||||
func (s *state) AddHead(errStr, errType string) {
|
||||
if s.curSec > 0 {
|
||||
return
|
||||
}
|
||||
s.f.sections.head.doBefore(s)
|
||||
s.curSec = 1
|
||||
s.ansi = s.f.sections.head.ansi
|
||||
s.writeField(err_fmt.FieldNameError,errStr)
|
||||
s.writeField(err_fmt.FieldNameType ,errType)
|
||||
s.f.sections.head.doAfter (s)
|
||||
}
|
||||
|
||||
|
||||
func (s *state) AddFieldString (name string, value string ) {
|
||||
if s.curSec != 1 {
|
||||
return
|
||||
}
|
||||
s.writeField(name,value)
|
||||
}
|
||||
|
||||
func (s *state) AddFieldInt (name string, value int ) {
|
||||
if s.curSec != 1 {
|
||||
return
|
||||
}
|
||||
s.writeField(name,fmt.Sprintf(s.f.vLayouts.intLayout,value))
|
||||
}
|
||||
|
||||
func (s *state) AddFieldFloat (name string, value float64 ) {
|
||||
if s.curSec != 1 {
|
||||
return
|
||||
}
|
||||
s.writeField(name,fmt.Sprintf(s.f.vLayouts.floatLayout,value))
|
||||
}
|
||||
|
||||
func (s *state) AddFieldBool (name string, value bool ) {
|
||||
if s.curSec != 1 {
|
||||
return
|
||||
}
|
||||
s.writeField(name,fmt.Sprintf(s.f.vLayouts.boolLayout,value))
|
||||
}
|
||||
|
||||
func (s *state) AddFieldTime (name string, value time.Time) {
|
||||
if s.curSec != 1 {
|
||||
return
|
||||
}
|
||||
s.writeField(name,value.Format(s.f.vLayouts.timeLayout))
|
||||
}
|
||||
|
||||
func (s *state) AddFieldDate (name string, value time.Time) {
|
||||
if s.curSec != 1 {
|
||||
return
|
||||
}
|
||||
s.writeField(name,value.Format(s.f.vLayouts.dateLayout))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in new issue