wrap errors

Implement error wrapping so we catch all errors into a single error.
This commit is contained in:
2022-01-09 15:39:37 -05:00
parent b4419a6f8c
commit d13b263222
9 changed files with 86 additions and 107 deletions

View File

@@ -4,6 +4,7 @@ import (
`strings`
`github.com/godbus/dbus/v5`
`r00t2.io/goutils/multierr`
)
// isPrompt returns a boolean that is true if path is/requires a prompt(ed path) and false if it is/does not.
@@ -63,19 +64,27 @@ func pathIsValid(path interface{}) (ok bool, err error) {
/*
validConnPath condenses the checks for connIsValid and pathIsValid into one func due to how frequently this check is done.
err is a MultiError, which can be treated as an error.error. (See https://pkg.go.dev/builtin#error)
If err is not nil, it IS a *multierr.MultiError.
*/
func validConnPath(conn *dbus.Conn, path interface{}) (cr *ConnPathCheckResult, err error) {
var connErr error
var pathErr error
var errs *multierr.MultiError = multierr.NewMultiError()
cr = new(ConnPathCheckResult)
cr.ConnOK, connErr = connIsValid(conn)
cr.PathOK, pathErr = pathIsValid(path)
if cr.ConnOK, err = connIsValid(conn); err != nil {
errs.AddError(err)
err = nil
}
if cr.PathOK, err = pathIsValid(path); err != nil {
errs.AddError(err)
err = nil
}
err = NewErrors(connErr, pathErr)
if !errs.IsEmpty() {
err = errs
}
return
}