mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Refactored/reorganized utils
This commit is contained in:
parent
fe3c339195
commit
aefce13f57
5 changed files with 196 additions and 151 deletions
25
internal/util/error.go
Normal file
25
internal/util/error.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package util
|
||||
|
||||
import "fmt"
|
||||
|
||||
// FormatErrorList() is a wrapper function that unifies error list formatting
|
||||
// and makes printing error lists consistent.
|
||||
//
|
||||
// NOTE: The error returned IS NOT an error in itself and may be a bit misleading.
|
||||
// Instead, it is a single condensed error composed of all of the errors included
|
||||
// in the errList argument.
|
||||
func FormatErrorList(errList []error) error {
|
||||
var err error
|
||||
for i, e := range errList {
|
||||
err = fmt.Errorf("\t[%d] %v\n", i, e)
|
||||
i += 1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// HasErrors() is a simple wrapper function to check if an error list contains
|
||||
// errors. Having a function that clearly states its purpose helps to improve
|
||||
// readibility although it may seem pointless.
|
||||
func HasErrors(errList []error) bool {
|
||||
return len(errList) > 0
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue