mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Caption support (#2462)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
71
vendor/github.com/asticode/go-astikit/errors.go
generated
vendored
Normal file
71
vendor/github.com/asticode/go-astikit/errors.go
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
package astikit
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Errors is an error containing multiple errors
|
||||
type Errors struct {
|
||||
m *sync.Mutex // Locks p
|
||||
p []error
|
||||
}
|
||||
|
||||
// NewErrors creates new errors
|
||||
func NewErrors(errs ...error) *Errors {
|
||||
return &Errors{
|
||||
m: &sync.Mutex{},
|
||||
p: errs,
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds a new error
|
||||
func (errs *Errors) Add(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
errs.m.Lock()
|
||||
defer errs.m.Unlock()
|
||||
errs.p = append(errs.p, err)
|
||||
}
|
||||
|
||||
// IsNil checks whether the error is nil
|
||||
func (errs *Errors) IsNil() bool {
|
||||
errs.m.Lock()
|
||||
defer errs.m.Unlock()
|
||||
return len(errs.p) == 0
|
||||
}
|
||||
|
||||
// Loop loops through the errors
|
||||
func (errs *Errors) Loop(fn func(idx int, err error) bool) {
|
||||
errs.m.Lock()
|
||||
defer errs.m.Unlock()
|
||||
for idx, err := range errs.p {
|
||||
if stop := fn(idx, err); stop {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Error implements the error interface
|
||||
func (errs *Errors) Error() string {
|
||||
errs.m.Lock()
|
||||
defer errs.m.Unlock()
|
||||
var ss []string
|
||||
for _, err := range errs.p {
|
||||
ss = append(ss, err.Error())
|
||||
}
|
||||
return strings.Join(ss, " && ")
|
||||
}
|
||||
|
||||
// ErrorCause returns the cause of an error
|
||||
func ErrorCause(err error) error {
|
||||
for {
|
||||
if u := errors.Unwrap(err); u != nil {
|
||||
err = u
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user