You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.9 KiB
101 lines
1.9 KiB
// ------------------------------------------------------------------------
|
|
// Project active2
|
|
// Active Thing (activething.com) git.activething.com/go
|
|
//
|
|
// File name error_list.go
|
|
// Created by DEV
|
|
// Modified 21/03/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 errs
|
|
|
|
|
|
type (
|
|
|
|
ErrList []error
|
|
|
|
)
|
|
|
|
|
|
func MakeErrList (err ...error) ErrList {
|
|
return append([]error(nil),err ...) }
|
|
|
|
|
|
|
|
func (l ErrList) Any () bool {
|
|
for _,e := range l {
|
|
if e != nil {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
|
|
func (l ErrList) Len () int {
|
|
return len(l) }
|
|
|
|
|
|
func (l ErrList) Count () int {
|
|
c:=0
|
|
for _,e := range l {
|
|
if e != nil {
|
|
c++
|
|
}
|
|
}
|
|
return c
|
|
}
|
|
|
|
|
|
func (l ErrList) First () error {
|
|
for _,e := range l {
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (l ErrList) Last () error {
|
|
for i := len(l) - 1; i >= 0; i-- {
|
|
if l[i] != nil {
|
|
return l[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Clean removes any nil errors from the list.
|
|
func (l ErrList) Clean() ErrList {
|
|
return l.filter(func(e error) bool {
|
|
return e != nil }) }
|
|
|
|
|
|
func (l ErrList) filter(filter func(error) bool) ErrList {
|
|
rs := make([]error, 0, len(l))
|
|
for _, e := range l {
|
|
if filter(e) {
|
|
rs = append(rs, e)
|
|
}
|
|
}
|
|
return rs
|
|
}
|