5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-28 15:55:40 +00:00
matterbridge/vendor/go.mau.fi/libsignal/util/errorhelper/ErrorHelper.go
2022-03-20 14:57:48 +01:00

41 lines
773 B
Go

package errorhelper
// NewMultiError returns a new MultiError object.
func NewMultiError() *MultiError {
return &MultiError{
errors: []error{},
}
}
// MultiError is a structure for holding multiple errors so they
// can be checked at a later point.
type MultiError struct {
errors []error
}
// Add will add the given error if it is not nil.
func (m *MultiError) Add(err error) {
if err != nil {
m.errors = append(m.errors, err)
}
}
// HasErrors will return true if any non-nil errors have been
// added.
func (m *MultiError) HasErrors() bool {
if len(m.errors) > 0 {
return true
}
return false
}
// Error will print the first error is encountered.
func (m *MultiError) Error() string {
if !m.HasErrors() {
return ""
}
return m.errors[0].Error()
}