5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-28 21:51:35 +00:00
matterbridge/vendor/go.mau.fi/libsignal/util/errorhelper/ErrorHelper.go

41 lines
773 B
Go
Raw Normal View History

2022-01-30 23:27:37 +00:00
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()
}