diff options
author | 2025-03-09 17:47:56 +0100 | |
---|---|---|
committer | 2025-03-10 01:59:49 +0100 | |
commit | 3ac1ee16f377d31a0fb80c8dae28b6239ac4229e (patch) | |
tree | f61faa581feaaeaba2542b9f2b8234a590684413 /vendor/codeberg.org/gruf/go-errors/v2 | |
parent | [chore] update URLs to forked source (diff) | |
download | gotosocial-3ac1ee16f377d31a0fb80c8dae28b6239ac4229e.tar.xz |
[chore] remove vendor
Diffstat (limited to 'vendor/codeberg.org/gruf/go-errors/v2')
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/LICENSE | 9 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/README.md | 8 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/build_caller.go | 26 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/build_nocaller.go | 18 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/build_notrace.go | 20 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/build_trace.go | 27 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/errors.go | 248 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/once.go | 31 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/runtime.go | 97 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/standard.go | 82 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-errors/v2/value.go | 50 |
11 files changed, 0 insertions, 616 deletions
diff --git a/vendor/codeberg.org/gruf/go-errors/v2/LICENSE b/vendor/codeberg.org/gruf/go-errors/v2/LICENSE deleted file mode 100644 index e4163ae35..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) 2022 gruf - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/codeberg.org/gruf/go-errors/v2/README.md b/vendor/codeberg.org/gruf/go-errors/v2/README.md deleted file mode 100644 index 21f7cb767..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# go-errors - -powerful errors library with a simple API that allows: -- accessing all the standard library errors functions -- wrapping of errors -- adding values to errors, in a similar manner to contexts -- including calling function prefix when tag=errcaller is set -- including stacktrace with error when tag=errtrace is set diff --git a/vendor/codeberg.org/gruf/go-errors/v2/build_caller.go b/vendor/codeberg.org/gruf/go-errors/v2/build_caller.go deleted file mode 100644 index ad5067574..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/build_caller.go +++ /dev/null @@ -1,26 +0,0 @@ -//go:build errcaller -// +build errcaller - -package errors - -import ( - _ "unsafe" -) - -// IncludesCaller is a compile-time flag used to indicate whether -// to include calling function prefix on error wrap / creation. -const IncludesCaller = true - -type caller string - -// set will set the actual caller value -// only when correct build flag is set. -func (c *caller) set(v string) { - *c = caller(v) -} - -// value returns the actual caller value -// only when correct build flag is set -func (c caller) value() string { - return string(c) -} diff --git a/vendor/codeberg.org/gruf/go-errors/v2/build_nocaller.go b/vendor/codeberg.org/gruf/go-errors/v2/build_nocaller.go deleted file mode 100644 index 935283bf5..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/build_nocaller.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build !errcaller -// +build !errcaller - -package errors - -// IncludesCaller is a compile-time flag used to indicate whether -// to include calling function prefix on error wrap / creation. -const IncludesCaller = false - -type caller struct{} - -// set will set the actual caller value -// only when correct build flag is set. -func (caller) set(string) {} - -// value returns the actual caller value -// only when correct build flag is set. -func (caller) value() string { return "" } diff --git a/vendor/codeberg.org/gruf/go-errors/v2/build_notrace.go b/vendor/codeberg.org/gruf/go-errors/v2/build_notrace.go deleted file mode 100644 index acee2e698..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/build_notrace.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build !errtrace -// +build !errtrace - -package errors - -import "runtime" - -// IncludesStacktrace is a compile-time flag used to indicate -// whether to include stacktraces on error wrap / creation. -const IncludesStacktrace = false - -type trace struct{} - -// set will set the actual trace value -// only when correct build flag is set. -func (trace) set([]runtime.Frame) {} - -// value returns the actual trace value -// only when correct build flag is set. -func (trace) value() Callers { return nil } diff --git a/vendor/codeberg.org/gruf/go-errors/v2/build_trace.go b/vendor/codeberg.org/gruf/go-errors/v2/build_trace.go deleted file mode 100644 index e7b652699..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/build_trace.go +++ /dev/null @@ -1,27 +0,0 @@ -//go:build errtrace -// +build errtrace - -package errors - -import ( - "runtime" - _ "unsafe" -) - -// IncludesStacktrace is a compile-time flag used to indicate -// whether to include stacktraces on error wrap / creation. -const IncludesStacktrace = true - -type trace []runtime.Frame - -// set will set the actual trace value -// only when correct build flag is set. -func (t *trace) set(v []runtime.Frame) { - *t = trace(v) -} - -// value returns the actual trace value -// only when correct build flag is set. -func (t trace) value() Callers { - return Callers(t) -} diff --git a/vendor/codeberg.org/gruf/go-errors/v2/errors.go b/vendor/codeberg.org/gruf/go-errors/v2/errors.go deleted file mode 100644 index d5f1a7ab1..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/errors.go +++ /dev/null @@ -1,248 +0,0 @@ -package errors - -import ( - "fmt" - "runtime" -) - -// New returns a new error created from message. -// -// Note this function cannot be inlined, to ensure expected -// and consistent behaviour in setting trace / caller info. -// -//go:noinline -func New(msg string) error { - var c caller - var t trace - if IncludesCaller { - pcs := make([]uintptr, 1) - _ = runtime.Callers(2, pcs) - fn := runtime.FuncForPC(pcs[0]) - c.set(funcName(fn)) - } - if IncludesStacktrace { - pcs := make([]uintptr, 10) - n := runtime.Callers(2, pcs) - iter := runtime.CallersFrames(pcs[:n]) - t.set(gatherFrames(iter, n)) - } - return &_errormsg{ - cfn: c, - msg: msg, - trc: t, - } -} - -// Newf returns a new error created from message format and args. -// -// Note this function cannot be inlined, to ensure expected -// and consistent behaviour in setting trace / caller info. -// -//go:noinline -func Newf(msgf string, args ...interface{}) error { - var c caller - var t trace - if IncludesCaller { - pcs := make([]uintptr, 1) - _ = runtime.Callers(2, pcs) - fn := runtime.FuncForPC(pcs[0]) - c.set(funcName(fn)) - } - if IncludesStacktrace { - pcs := make([]uintptr, 10) - n := runtime.Callers(2, pcs) - iter := runtime.CallersFrames(pcs[:n]) - t.set(gatherFrames(iter, n)) - } - return &_errormsg{ - cfn: c, - msg: fmt.Sprintf(msgf, args...), - trc: t, - } -} - -// NewAt returns a new error created, skipping 'skip' -// frames for trace / caller information, from message. -// -// Note this function cannot be inlined, to ensure expected -// and consistent behaviour in setting trace / caller info. -// -//go:noinline -func NewAt(skip int, msg string) error { - var c caller - var t trace - if IncludesCaller { - pcs := make([]uintptr, 1) - _ = runtime.Callers(skip+1, pcs) - fn := runtime.FuncForPC(pcs[0]) - c.set(funcName(fn)) - } - if IncludesStacktrace { - pcs := make([]uintptr, 10) - n := runtime.Callers(skip+1, pcs) - iter := runtime.CallersFrames(pcs[:n]) - t.set(gatherFrames(iter, n)) - } - return &_errormsg{ - cfn: c, - msg: msg, - trc: t, - } -} - -// Wrap will wrap supplied error within a new error created from message. -// -// Note this function cannot be inlined, to ensure expected -// and consistent behaviour in setting trace / caller info. -// -//go:noinline -func Wrap(err error, msg string) error { - if err == nil { - panic("cannot wrap nil error") - } - var c caller - var t trace - if IncludesCaller { - pcs := make([]uintptr, 1) - _ = runtime.Callers(2, pcs) - fn := runtime.FuncForPC(pcs[0]) - c.set(funcName(fn)) - } - if IncludesStacktrace { - pcs := make([]uintptr, 10) - n := runtime.Callers(2, pcs) - iter := runtime.CallersFrames(pcs[:n]) - t.set(gatherFrames(iter, n)) - } - return &_errorwrap{ - cfn: c, - msg: msg, - err: err, - trc: t, - } -} - -// Wrapf will wrap supplied error within a new error created from message format and args. -// -// Note this function cannot be inlined, to ensure expected -// and consistent behaviour in setting trace / caller info. -// -//go:noinline -func Wrapf(err error, msgf string, args ...interface{}) error { - if err == nil { - panic("cannot wrap nil error") - } - var c caller - var t trace - if IncludesCaller { - pcs := make([]uintptr, 1) - _ = runtime.Callers(2, pcs) - fn := runtime.FuncForPC(pcs[0]) - c.set(funcName(fn)) - } - if IncludesStacktrace { - pcs := make([]uintptr, 10) - n := runtime.Callers(2, pcs) - iter := runtime.CallersFrames(pcs[:n]) - t.set(gatherFrames(iter, n)) - } - return &_errorwrap{ - cfn: c, - msg: fmt.Sprintf(msgf, args...), - err: err, - trc: t, - } -} - -// WrapAt wraps error within new error created from message, -// skipping 'skip' frames for trace / caller information. -// -// Note this function cannot be inlined, to ensure expected -// and consistent behaviour in setting trace / caller info. -// -//go:noinline -func WrapAt(skip int, err error, msg string) error { - if err == nil { - panic("cannot wrap nil error") - } - var c caller - var t trace - if IncludesCaller { - pcs := make([]uintptr, 1) - _ = runtime.Callers(skip+1, pcs) - fn := runtime.FuncForPC(pcs[0]) - c.set(funcName(fn)) - } - if IncludesStacktrace { - pcs := make([]uintptr, 10) - n := runtime.Callers(skip+1, pcs) - iter := runtime.CallersFrames(pcs[:n]) - t.set(gatherFrames(iter, n)) - } - return &_errorwrap{ - cfn: c, - msg: msg, - err: err, - trc: t, - } -} - -// Stacktrace fetches first stored stacktrace of callers from error chain. -func Stacktrace(err error) Callers { - if !IncludesStacktrace { - // compile-time check - return nil - } - if e := AsV2[*_errormsg](err); err != nil { - return e.trc.value() - } - if e := AsV2[*_errorwrap](err); err != nil { - return e.trc.value() - } - return nil -} - -type _errormsg struct { - cfn caller - msg string - trc trace -} - -func (err *_errormsg) Error() string { - if IncludesCaller { - fn := err.cfn.value() - return fn + " " + err.msg - } else { - return err.msg - } -} - -func (err *_errormsg) Is(other error) bool { - oerr, ok := other.(*_errormsg) - return ok && oerr.msg == err.msg -} - -type _errorwrap struct { - cfn caller - msg string - err error // wrapped - trc trace -} - -func (err *_errorwrap) Error() string { - if IncludesCaller { - fn := err.cfn.value() - return fn + " " + err.msg + ": " + err.err.Error() - } else { - return err.msg + ": " + err.err.Error() - } -} - -func (err *_errorwrap) Is(other error) bool { - oerr, ok := other.(*_errorwrap) - return ok && oerr.msg == err.msg -} - -func (err *_errorwrap) Unwrap() error { - return err.err -} diff --git a/vendor/codeberg.org/gruf/go-errors/v2/once.go b/vendor/codeberg.org/gruf/go-errors/v2/once.go deleted file mode 100644 index 467fe726d..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/once.go +++ /dev/null @@ -1,31 +0,0 @@ -package errors - -import ( - "sync/atomic" -) - -// OnceError is an error structure that supports safe multi -// threaded usage and setting only once (until reset). -type OnceError struct{ ptr atomic.Pointer[error] } - -// Store will safely set the OnceError to value, no-op if nil. -func (e *OnceError) Store(err error) bool { - if err == nil { - return false - } - return e.ptr.CompareAndSwap(nil, &err) -} - -// Load will load the currently stored error. -func (e *OnceError) Load() error { - if ptr := e.ptr.Load(); ptr != nil { - return *ptr - } - return nil -} - -// IsSet returns whether OnceError has been set. -func (e *OnceError) IsSet() bool { return (e.ptr.Load() != nil) } - -// Reset will reset the OnceError value. -func (e *OnceError) Reset() { e.ptr.Store(nil) } diff --git a/vendor/codeberg.org/gruf/go-errors/v2/runtime.go b/vendor/codeberg.org/gruf/go-errors/v2/runtime.go deleted file mode 100644 index 0c8cf11cd..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/runtime.go +++ /dev/null @@ -1,97 +0,0 @@ -package errors - -import ( - "encoding/json" - "runtime" - "strconv" - "strings" - "unsafe" -) - -// Callers ... -type Callers []runtime.Frame - -// MarshalJSON implements json.Marshaler to provide an easy, simple default. -func (c Callers) MarshalJSON() ([]byte, error) { - // JSON-able frame type - type jsonFrame struct { - Func string `json:"func"` - File string `json:"file"` - Line int `json:"line"` - } - - // Allocate expected size jsonFrame slice - jsonFrames := make([]jsonFrame, len(c)) - - // Convert each to jsonFrame object - for i := 0; i < len(c); i++ { - frame := c[i] - jsonFrames[i] = jsonFrame{ - Func: funcName(frame.Func), - File: frame.File, - Line: frame.Line, - } - } - - // marshal converted frames - return json.Marshal(jsonFrames) -} - -// String will return a simple string representation of receiving Callers slice. -func (c Callers) String() string { - // Guess-timate to reduce allocs - buf := make([]byte, 0, 64*len(c)) - - for i := 0; i < len(c); i++ { - frame := c[i] - - // Append formatted caller info - fn := funcName(frame.Func) - buf = append(buf, fn+"()\n\t"+frame.File+":"...) - buf = strconv.AppendInt(buf, int64(frame.Line), 10) - buf = append(buf, '\n') - } - - return *(*string)(unsafe.Pointer(&buf)) -} - -// funcName formats a function name to a quickly-readable string. -func funcName(fn *runtime.Func) string { - if fn == nil { - return "" - } - - // Get func name - // for formatting. - name := fn.Name() - - // Drop all but the package name and function name, no mod path - if idx := strings.LastIndex(name, "/"); idx >= 0 { - name = name[idx+1:] - } - - const params = `[...]` - - // Drop any generic type parameter markers - if idx := strings.Index(name, params); idx >= 0 { - name = name[:idx] + name[idx+len(params):] - } - - return name -} - -// gatherFrames collates runtime frames from a frame iterator. -func gatherFrames(iter *runtime.Frames, n int) Callers { - if iter == nil { - return nil - } - frames := make([]runtime.Frame, 0, n) - for { - f, ok := iter.Next() - if !ok { - break - } - frames = append(frames, f) - } - return frames -} diff --git a/vendor/codeberg.org/gruf/go-errors/v2/standard.go b/vendor/codeberg.org/gruf/go-errors/v2/standard.go deleted file mode 100644 index e1d7d1440..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/standard.go +++ /dev/null @@ -1,82 +0,0 @@ -package errors - -import ( - "errors" -) - -// See: errors.Is(). -func Is(err error, target error) bool { return errors.Is(err, target) } - -// IsV2 calls Is(err, target) for each target within targets. -func IsV2(err error, targets ...error) bool { - for _, target := range targets { - if Is(err, target) { - return true - } - } - return false -} - -// See: errors.As(). -func As(err error, target any) bool { return errors.As(err, target) } - -// AsV2 is functionally similar to As(), instead -// leveraging generics to handle allocation and -// returning of a concrete generic parameter type. -func AsV2[Type any](err error) Type { - var t Type - var ok bool - errs := []error{err} - for len(errs) > 0 { - // Pop next error to check. - err := errs[len(errs)-1] - errs = errs[:len(errs)-1] - - // Check direct type. - t, ok = err.(Type) - if ok { - return t - } - - // Look for .As() support. - as, ok := err.(interface { - As(target any) bool - }) - - if ok { - // Attempt .As(). - if as.As(&t) { - return t - } - } - - // Try unwrap errors. - switch u := err.(type) { - case interface{ Unwrap() error }: - errs = append(errs, u.Unwrap()) - case interface{ Unwrap() []error }: - errs = append(errs, u.Unwrap()...) - } - } - return t -} - -// See: errors.Unwrap(). -func Unwrap(err error) error { return errors.Unwrap(err) } - -// UnwrapV2 is functionally similar to Unwrap(), except that -// it also handles the case of interface{ Unwrap() []error }. -func UnwrapV2(err error) []error { - switch u := err.(type) { - case interface{ Unwrap() error }: - if e := u.Unwrap(); err != nil { - return []error{e} - } - case interface{ Unwrap() []error }: - return u.Unwrap() - } - return nil -} - -// See: errors.Join(). -func Join(errs ...error) error { return errors.Join(errs...) } diff --git a/vendor/codeberg.org/gruf/go-errors/v2/value.go b/vendor/codeberg.org/gruf/go-errors/v2/value.go deleted file mode 100644 index 876e5f80e..000000000 --- a/vendor/codeberg.org/gruf/go-errors/v2/value.go +++ /dev/null @@ -1,50 +0,0 @@ -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") - } - var kvs []kv - if e := AsV2[*errWithValues](err); e != nil { - kvs = e.kvs - } - return &errWithValues{ - err: err, - kvs: append(kvs, kv{key, value}), - } -} - -// Value searches for value stored under given key in error chain. -func Value(err error, key any) any { - if e := AsV2[*errWithValues](err); e != nil { - return e.Value(key) - } - return nil -} - -// simple key-value type. -type kv struct{ k, v any } - -// errWithValues wraps an error to provide key-value storage. -type errWithValues struct { - err error - kvs []kv -} - -func (e *errWithValues) Error() string { - return e.err.Error() -} - -func (e *errWithValues) Unwrap() error { - return e.err -} - -func (e *errWithValues) Value(key any) any { - for i := range e.kvs { - if e.kvs[i].k == key { - return e.kvs[i].v - } - } - return nil -} |