From 7472d1e70bcbbf69d5d26a4b61699db3fcb3a294 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Fri, 19 Feb 2021 10:08:38 +0800 Subject: [PATCH] fix golint issues in core/errorx (#480) --- core/errorx/batcherror.go | 5 +++++ core/errorx/callchain.go | 1 + 2 files changed, 6 insertions(+) diff --git a/core/errorx/batcherror.go b/core/errorx/batcherror.go index dc83ab36..ec8ef0dc 100644 --- a/core/errorx/batcherror.go +++ b/core/errorx/batcherror.go @@ -3,6 +3,7 @@ package errorx import "bytes" type ( + // A BatchError is an error that can hold multiple errors. BatchError struct { errs errorArray } @@ -10,12 +11,14 @@ type ( errorArray []error ) +// Add adds err to be. func (be *BatchError) Add(err error) { if err != nil { be.errs = append(be.errs, err) } } +// Err returns an error that represents all errors. func (be *BatchError) Err() error { switch len(be.errs) { case 0: @@ -27,10 +30,12 @@ func (be *BatchError) Err() error { } } +// NotNil checks if any error inside. func (be *BatchError) NotNil() bool { return len(be.errs) > 0 } +// Error returns a string that represents inside errors. func (ea errorArray) Error() string { var buf bytes.Buffer diff --git a/core/errorx/callchain.go b/core/errorx/callchain.go index fb9226b7..dbdab05c 100644 --- a/core/errorx/callchain.go +++ b/core/errorx/callchain.go @@ -1,5 +1,6 @@ package errorx +// Chain runs funs one by one until an error occurred. func Chain(fns ...func() error) error { for _, fn := range fns { if err := fn(); err != nil {