Refactored/reorganized utils

This commit is contained in:
David Allen 2024-07-24 11:52:12 -06:00
parent fe3c339195
commit aefce13f57
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
5 changed files with 196 additions and 151 deletions

25
internal/util/error.go Normal file
View 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
}