summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-errors
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-01-17 11:25:13 +0000
committerLibravatar GitHub <noreply@github.com>2023-01-17 11:25:13 +0000
commita6c6bdb34ab668ab810308e63325a891e404e434 (patch)
tree12be85a203123dbaa602e8173343c015d5149047 /vendor/codeberg.org/gruf/go-errors
parent[bugfix] Parse video metadata more accurately; allow Range in fileserver (#1342) (diff)
downloadgotosocial-a6c6bdb34ab668ab810308e63325a891e404e434.tar.xz
[chore]: Bump codeberg.org/gruf/go-errors/v2 from 2.0.2 to 2.1.1 (#1346)
Bumps codeberg.org/gruf/go-errors/v2 from 2.0.2 to 2.1.1. --- updated-dependencies: - dependency-name: codeberg.org/gruf/go-errors/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-errors')
-rw-r--r--vendor/codeberg.org/gruf/go-errors/v2/callers.go34
-rw-r--r--vendor/codeberg.org/gruf/go-errors/v2/errors.go12
-rw-r--r--vendor/codeberg.org/gruf/go-errors/v2/standard.go54
-rw-r--r--vendor/codeberg.org/gruf/go-errors/v2/value.go54
4 files changed, 103 insertions, 51 deletions
diff --git a/vendor/codeberg.org/gruf/go-errors/v2/callers.go b/vendor/codeberg.org/gruf/go-errors/v2/callers.go
index 77a2c1c1b..3fe84b0c5 100644
--- a/vendor/codeberg.org/gruf/go-errors/v2/callers.go
+++ b/vendor/codeberg.org/gruf/go-errors/v2/callers.go
@@ -40,33 +40,29 @@ func (f Callers) Frames() []runtime.Frame {
return frames
}
-// MarshalJSON implements json.Marshaler to provide an easy, simply default.
+// MarshalJSON implements json.Marshaler to provide an easy, simple default.
func (f Callers) MarshalJSON() ([]byte, error) {
// JSON-able frame type
- type frame struct {
+ type jsonFrame struct {
Func string `json:"func"`
File string `json:"file"`
Line int `json:"line"`
}
- // Allocate expected frames slice
- frames := make([]frame, 0, len(f))
+ // Convert to frames
+ frames := f.Frames()
- // Get frames iterator for PCs
- iter := runtime.CallersFrames(f)
+ // Allocate expected size jsonFrame slice
+ jsonFrames := make([]jsonFrame, 0, len(f))
- for {
- // Get next frame
- f, ok := iter.Next()
- if !ok {
- break
- }
+ for i := 0; i < len(frames); i++ {
+ frame := frames[i]
- // Append to frames slice
- frames = append(frames, frame{
- Func: funcname(f.Function),
- File: f.File,
- Line: f.Line,
+ // Convert each to jsonFrame object
+ jsonFrames = append(jsonFrames, jsonFrame{
+ Func: funcname(frame.Function),
+ File: frame.File,
+ Line: frame.Line,
})
}
@@ -86,8 +82,8 @@ func (f Callers) String() string {
frame := frames[i]
// Append formatted caller info
- funcname := funcname(frame.Function)
- buf = append(buf, funcname+"()\n\t"+frame.File+":"...)
+ fn := funcname(frame.Function)
+ buf = append(buf, fn+"()\n\t"+frame.File+":"...)
buf = strconv.AppendInt(buf, int64(frame.Line), 10)
buf = append(buf, '\n')
}
diff --git a/vendor/codeberg.org/gruf/go-errors/v2/errors.go b/vendor/codeberg.org/gruf/go-errors/v2/errors.go
index 180fc6799..18f780994 100644
--- a/vendor/codeberg.org/gruf/go-errors/v2/errors.go
+++ b/vendor/codeberg.org/gruf/go-errors/v2/errors.go
@@ -24,13 +24,13 @@ func Wrapf(err error, msgf string, args ...interface{}) error {
return create(fmt.Sprintf(msgf, args...), err)
}
-// Stacktrace fetches a stored stacktrace of callers from an error, or returns nil.
+// Stacktrace fetches first stored stacktrace of callers from error chain.
func Stacktrace(err error) Callers {
- var callers Callers
- if err, ok := err.(interface { //nolint
+ var e interface {
Stacktrace() Callers
- }); ok {
- callers = err.Stacktrace()
}
- return callers
+ if !As(err, &e) {
+ return nil
+ }
+ return e.Stacktrace()
}
diff --git a/vendor/codeberg.org/gruf/go-errors/v2/standard.go b/vendor/codeberg.org/gruf/go-errors/v2/standard.go
index 2a4671153..e58364bb3 100644
--- a/vendor/codeberg.org/gruf/go-errors/v2/standard.go
+++ b/vendor/codeberg.org/gruf/go-errors/v2/standard.go
@@ -3,6 +3,7 @@ package errors
import (
"errors"
"reflect"
+ _ "unsafe"
"codeberg.org/gruf/go-bitutil"
)
@@ -18,7 +19,7 @@ import (
func Is(err error, targets ...error) bool {
var flags bitutil.Flags64
- // Flags only has 64 bit slots
+ // Flags only has 64 bit-slots
if len(targets) > 64 {
panic("too many targets")
}
@@ -46,26 +47,30 @@ func Is(err error, targets ...error) bool {
}
for err != nil {
- var errorIs func(error) bool
-
// Check if this layer supports .Is interface
is, ok := err.(interface{ Is(error) bool })
- if ok {
- errorIs = is.Is
- } else {
- errorIs = neveris
- }
- for i := 0; i < len(targets); i++ {
- // Try directly compare errors
- if flags.Get(uint8(i)) &&
- err == targets[i] {
- return true
+ if !ok {
+ // Error does not support interface
+ //
+ // Only try perform direct compare
+ for i := 0; i < len(targets); i++ {
+ // Try directly compare errors
+ if flags.Get(uint8(i)) &&
+ err == targets[i] {
+ return true
+ }
}
-
- // Try use .Is() interface
- if errorIs(targets[i]) {
- return true
+ } else {
+ // Error supports the .Is interface
+ //
+ // Perform direct compare AND .Is()
+ for i := 0; i < len(targets); i++ {
+ if (flags.Get(uint8(i)) &&
+ err == targets[i]) ||
+ is.Is(targets[i]) {
+ return true
+ }
}
}
@@ -92,15 +97,12 @@ func Is(err error, targets ...error) bool {
//
// As panics if target is not a non-nil pointer to either a type that implements
// error, or to any interface type.
-func As(err error, target interface{}) bool {
- return errors.As(err, target)
-}
+//
+//go:linkname As errors.As
+func As(err error, target interface{}) bool
// Unwrap returns the result of calling the Unwrap method on err, if err's
// type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.
-func Unwrap(err error) error {
- return errors.Unwrap(err)
-}
-
-// neveris fits the .Is(error) bool interface function always returning false.
-func neveris(error) bool { return false }
+//
+//go:linkname Unwrap errors.Unwrap
+func Unwrap(err error) error
diff --git a/vendor/codeberg.org/gruf/go-errors/v2/value.go b/vendor/codeberg.org/gruf/go-errors/v2/value.go
new file mode 100644
index 000000000..6a1f64451
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-errors/v2/value.go
@@ -0,0 +1,54 @@
+package errors
+
+// WithValue wraps err to store given key-value pair, accessible via Value() function.
+func WithValue(err error, key any, value any) error {
+ if err == nil {
+ panic("nil error")
+ }
+ return &errWithValue{
+ err: err,
+ key: key,
+ val: value,
+ }
+}
+
+// Value searches for value stored under given key in error chain.
+func Value(err error, key any) any {
+ var e *errWithValue
+
+ if !As(err, &e) {
+ return nil
+ }
+
+ return e.Value(key)
+}
+
+type errWithValue struct {
+ err error
+ key any
+ val any
+}
+
+func (e *errWithValue) Error() string {
+ return e.err.Error()
+}
+
+func (e *errWithValue) Is(target error) bool {
+ return e.err == target
+}
+
+func (e *errWithValue) Unwrap() error {
+ return Unwrap(e.err)
+}
+
+func (e *errWithValue) Value(key any) any {
+ for {
+ if key == e.key {
+ return e.val
+ }
+
+ if !As(e.err, &e) {
+ return nil
+ }
+ }
+}