35 lines
569 B
Go
35 lines
569 B
Go
package errors
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func WarpErrs(es ...error) (err error) {
|
|
for idx, e := range es {
|
|
if idx == 0 {
|
|
err = fmt.Errorf("[%d]: %w", idx, e)
|
|
continue
|
|
}
|
|
err = fmt.Errorf("%s\n[%d]: %w", err.Error(), idx, e)
|
|
}
|
|
return
|
|
}
|
|
|
|
const (
|
|
WarpNameFormat = "err[%s]"
|
|
)
|
|
|
|
func WarpErrsWithName(name string, es ...error) (err error) {
|
|
if len(es) == 0 {
|
|
return nil
|
|
}
|
|
for idx, e := range es {
|
|
if idx == 0 {
|
|
err = fmt.Errorf(WarpNameFormat+" [%d]: %w", name, idx, e)
|
|
continue
|
|
}
|
|
err = fmt.Errorf("%s\n[%d]: %w", err.Error(), idx, e)
|
|
}
|
|
return
|
|
}
|