summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/libsignal/util/errorhelper
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.mau.fi/libsignal/util/errorhelper')
-rw-r--r--vendor/go.mau.fi/libsignal/util/errorhelper/ErrorHelper.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/go.mau.fi/libsignal/util/errorhelper/ErrorHelper.go b/vendor/go.mau.fi/libsignal/util/errorhelper/ErrorHelper.go
new file mode 100644
index 00000000..b30adb0a
--- /dev/null
+++ b/vendor/go.mau.fi/libsignal/util/errorhelper/ErrorHelper.go
@@ -0,0 +1,40 @@
+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()
+}