parent
d43d13c37f
commit
70814fe835
@ -0,0 +1,73 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name show.go
|
||||
// Created by DEV
|
||||
// Modified 07/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
|
||||
|
||||
|
||||
const (
|
||||
|
||||
ShowWrapped BuilderOption = 1 << iota
|
||||
ShowType
|
||||
ShowAnsi
|
||||
ShowIndent
|
||||
ShowFields
|
||||
ShowCause
|
||||
ShowTrace
|
||||
ShowFieldEmpty
|
||||
|
||||
showDefault = ShowWrapped | ShowType | ShowAnsi | ShowIndent | ShowFields | ShowCause | ShowTrace
|
||||
)
|
||||
|
||||
|
||||
type (
|
||||
|
||||
BuilderOption uint8
|
||||
)
|
||||
|
||||
|
||||
func (s BuilderOption) SetDefaults () BuilderOption {
|
||||
return showDefault }
|
||||
|
||||
func (s BuilderOption) ShowWrapped () bool {
|
||||
return s&ShowWrapped !=0 }
|
||||
|
||||
func (s BuilderOption) ShowType () bool {
|
||||
return s&ShowType !=0 }
|
||||
|
||||
func (s BuilderOption) ShowAnsi () bool {
|
||||
return s&ShowAnsi !=0 }
|
||||
|
||||
func (s BuilderOption) ShowIndent () bool {
|
||||
return s&ShowIndent !=0 }
|
||||
|
||||
func (s BuilderOption) ShowFields() bool {
|
||||
return s&ShowFields !=0 }
|
||||
|
||||
func (s BuilderOption) ShowCause () bool {
|
||||
return s&ShowCause !=0 }
|
||||
|
||||
func (s BuilderOption) ShowTrace () bool {
|
||||
return s&ShowTrace !=0 }
|
||||
|
||||
func (s BuilderOption) ShowFieldEmpty () bool {
|
||||
return s&ShowFieldEmpty !=0 }
|
||||
@ -0,0 +1,38 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name field.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
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
|
||||
field struct {
|
||||
n string
|
||||
v string
|
||||
f
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name fmt.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
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
TextErrorFormatter struct {}
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
func (f *TextErrorFormatter) Format (err error) []byte {
|
||||
|
||||
st := &state{
|
||||
f : f,
|
||||
}
|
||||
er :=
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name section.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"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
section struct {
|
||||
code ansi.Code
|
||||
|
||||
before err_fmt.BuildFnc
|
||||
after err_fmt.BuildFnc
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func (s *section) doBefore (b err_fmt.Builder) {
|
||||
if s != nil && s.before != nil {
|
||||
s.before.Build(b) } }
|
||||
|
||||
|
||||
func (s *section) doAfter (b err_fmt.Builder) {
|
||||
if s != nil && s.after != nil {
|
||||
s.after.Build(b) } }
|
||||
@ -0,0 +1,120 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name state.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 (
|
||||
"bytes"
|
||||
"errors"
|
||||
"errs/err_fmt"
|
||||
"errs/stack"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
|
||||
state struct {
|
||||
f *TextErrorFormatter
|
||||
b bytes.Buffer
|
||||
|
||||
|
||||
secs []*section
|
||||
flds []field
|
||||
cses []error
|
||||
trace stack.Trace
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func newState (f *TextErrorFormatter) *state {
|
||||
return &state {
|
||||
f : f,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (s *state) format (err error, unwrapping bool) (fe error) {
|
||||
|
||||
|
||||
|
||||
if fe,is := err.(err_fmt.Buildable); is {
|
||||
fe.Build(s)
|
||||
} else {
|
||||
rt := reflect.TypeOf(err)
|
||||
if rt.Kind() == reflect.Pointer {
|
||||
rt = rt.Elem()
|
||||
}
|
||||
eb := err_fmt.GetErrorTypeBuilder(rt)
|
||||
if eb != nil {
|
||||
eb.BuildError(s,err)
|
||||
} else {
|
||||
eb := err_fmt.MakeErrorTypeBuilder(s,err)
|
||||
err_fmt.SetErrorTypeBuilder(rt,eb)
|
||||
}
|
||||
}
|
||||
if unwrapping {
|
||||
return fe
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (s *state) unwrapError (err error) {
|
||||
uw := errors.Unwrap(err)
|
||||
for uw != nil {
|
||||
if ue := s.format(uw,true); ue != nil {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name text_fmt_field.go
|
||||
// Created by DEV
|
||||
// Modified 11/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 txt
|
||||
|
||||
type (
|
||||
|
||||
textFmtField struct {
|
||||
name string
|
||||
value string
|
||||
format *textFmtFieldFormat
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func newTextFmtField (name, value string, format *textFmtFieldFormat) *textFmtField {
|
||||
return &textFmtField{
|
||||
name : name,
|
||||
value : value,
|
||||
format: format }
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name text_fmt_field_format.go
|
||||
// Created by DEV
|
||||
// Modified 11/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 txt
|
||||
|
||||
import (
|
||||
"ansi"
|
||||
"atypes/astrings"
|
||||
"errs/erfmt"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
textFmtFieldFormat struct {
|
||||
NameAnsi ansi.Code
|
||||
ValueAnsi ansi.Code
|
||||
NameTrans astrings.Transformers
|
||||
ValueTrans astrings.Transformers
|
||||
BuildBefore erfmt.FormattableFnc
|
||||
BuildAfter erfmt.FormattableFnc
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
func (f textFmtFieldFormat) clone() textFmtFieldFormat {
|
||||
return textFmtFieldFormat{
|
||||
NameAnsi: f.NameAnsi,
|
||||
ValueAnsi: f.ValueAnsi,
|
||||
NameTrans: append(astrings.Transformers(nil),f.NameTrans...),
|
||||
ValueTrans: append(astrings.Transformers(nil),f.ValueTrans...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in new issue