util: Port all multierr code to new errwrap package
This cleans things up and simplifies a lot of the code. Also it's easier to just import one error package when needed.
This commit is contained in:
@@ -25,8 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/purpleidea/mgmt/util"
|
"github.com/purpleidea/mgmt/util"
|
||||||
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// New builds a new converger coordinator.
|
// New builds a new converger coordinator.
|
||||||
@@ -323,9 +322,8 @@ func (obj *Coordinator) runStateFns(converged bool) error {
|
|||||||
for _, name := range keys { // run in deterministic order
|
for _, name := range keys { // run in deterministic order
|
||||||
fn := obj.stateFns[name]
|
fn := obj.stateFns[name]
|
||||||
// call an arbitrary function
|
// call an arbitrary function
|
||||||
if e := fn(converged); e != nil {
|
e := fn(converged)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -378,7 +377,7 @@ Loop:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
failed = true
|
failed = true
|
||||||
close(obj.state[vertex].watchDone) // causes doneChan to close
|
close(obj.state[vertex].watchDone) // causes doneChan to close
|
||||||
reterr = multierr.Append(reterr, err) // permanent failure
|
reterr = errwrap.Append(reterr, err) // permanent failure
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if obj.Debug {
|
if obj.Debug {
|
||||||
@@ -459,7 +458,7 @@ Loop:
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
failed = true
|
failed = true
|
||||||
close(obj.state[vertex].limitDone) // causes doneChan to close
|
close(obj.state[vertex].limitDone) // causes doneChan to close
|
||||||
reterr = multierr.Append(reterr, e) // permanent failure
|
reterr = errwrap.Append(reterr, e) // permanent failure
|
||||||
break LimitWait
|
break LimitWait
|
||||||
}
|
}
|
||||||
if obj.Debug {
|
if obj.Debug {
|
||||||
@@ -499,7 +498,7 @@ Loop:
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
failed = true
|
failed = true
|
||||||
close(obj.state[vertex].limitDone) // causes doneChan to close
|
close(obj.state[vertex].limitDone) // causes doneChan to close
|
||||||
reterr = multierr.Append(reterr, e) // permanent failure
|
reterr = errwrap.Append(reterr, e) // permanent failure
|
||||||
break RetryWait
|
break RetryWait
|
||||||
}
|
}
|
||||||
if obj.Debug {
|
if obj.Debug {
|
||||||
@@ -547,7 +546,7 @@ Loop:
|
|||||||
// to exit right here... (It happens when we loop...)
|
// to exit right here... (It happens when we loop...)
|
||||||
failed = true
|
failed = true
|
||||||
close(obj.state[vertex].processDone) // causes doneChan to close
|
close(obj.state[vertex].processDone) // causes doneChan to close
|
||||||
reterr = multierr.Append(reterr, err) // permanent failure
|
reterr = errwrap.Append(reterr, err) // permanent failure
|
||||||
continue
|
continue
|
||||||
|
|
||||||
} // retry loop
|
} // retry loop
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/engine"
|
"github.com/purpleidea/mgmt/engine"
|
||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AutoEdge adds the automatic edges to the graph.
|
// AutoEdge adds the automatic edges to the graph.
|
||||||
@@ -49,7 +47,7 @@ func AutoEdge(graph *pgraph.Graph, debug bool, logf func(format string, v ...int
|
|||||||
for _, res := range sorted { // for each vertexes autoedges
|
for _, res := range sorted { // for each vertexes autoedges
|
||||||
autoEdgeObj, e := res.AutoEdges()
|
autoEdgeObj, e := res.AutoEdges()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = multierr.Append(err, e) // collect all errors
|
err = errwrap.Append(err, e) // collect all errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if autoEdgeObj == nil {
|
if autoEdgeObj == nil {
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
"github.com/purpleidea/mgmt/util/semaphore"
|
"github.com/purpleidea/mgmt/util/semaphore"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Engine encapsulates a generic graph and manages its operations.
|
// Engine encapsulates a generic graph and manages its operations.
|
||||||
@@ -380,20 +378,16 @@ func (obj *Engine) Pause(fastPause bool) error {
|
|||||||
|
|
||||||
// Close triggers a shutdown. Engine must be already paused before this is run.
|
// Close triggers a shutdown. Engine must be already paused before this is run.
|
||||||
func (obj *Engine) Close() error {
|
func (obj *Engine) Close() error {
|
||||||
var reterr error
|
emptyGraph, reterr := pgraph.NewGraph("empty")
|
||||||
|
|
||||||
emptyGraph, err := pgraph.NewGraph("empty")
|
|
||||||
if err != nil {
|
|
||||||
reterr = multierr.Append(reterr, err) // list of errors
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a graph switch (graph sync) that switches to an empty graph!
|
// this is a graph switch (graph sync) that switches to an empty graph!
|
||||||
if err := obj.Load(emptyGraph); err != nil { // copy in empty graph
|
if err := obj.Load(emptyGraph); err != nil { // copy in empty graph
|
||||||
reterr = multierr.Append(reterr, err)
|
reterr = errwrap.Append(reterr, err)
|
||||||
}
|
}
|
||||||
|
// FIXME: Do we want to run commit if Load failed? Does this even work?
|
||||||
// the commit will cause the graph sync to shut things down cleverly...
|
// the commit will cause the graph sync to shut things down cleverly...
|
||||||
if err := obj.Commit(); err != nil {
|
if err := obj.Commit(); err != nil {
|
||||||
reterr = multierr.Append(reterr, err)
|
reterr = errwrap.Append(reterr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.wg.Wait() // for now, this doesn't need to be a separate Wait() method
|
obj.wg.Wait() // for now, this doesn't need to be a separate Wait() method
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMultiErr(t *testing.T) {
|
func TestMultiErr(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
e := fmt.Errorf("some error")
|
e := fmt.Errorf("some error")
|
||||||
err = multierr.Append(err, e) // build an error from a nil base
|
err = errwrap.Append(err, e) // build an error from a nil base
|
||||||
// ensure that this lib allows us to append to a nil
|
// ensure that this lib allows us to append to a nil
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("missing error")
|
t.Errorf("missing error")
|
||||||
|
|||||||
@@ -23,9 +23,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
"github.com/purpleidea/mgmt/util/semaphore"
|
"github.com/purpleidea/mgmt/util/semaphore"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SemaSep is the trailing separator to split the semaphore id from the size.
|
// SemaSep is the trailing separator to split the semaphore id from the size.
|
||||||
@@ -46,9 +45,8 @@ func (obj *Engine) semaLock(semas []string) error {
|
|||||||
}
|
}
|
||||||
obj.slock.Unlock()
|
obj.slock.Unlock()
|
||||||
|
|
||||||
if err := sema.P(1); err != nil { // lock!
|
err := sema.P(1) // lock!
|
||||||
reterr = multierr.Append(reterr, err) // list of errors
|
reterr = errwrap.Append(reterr, err) // list of errors
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return reterr
|
return reterr
|
||||||
}
|
}
|
||||||
@@ -65,9 +63,8 @@ func (obj *Engine) semaUnlock(semas []string) error {
|
|||||||
panic(fmt.Sprintf("graph: sema: %s does not exist", id))
|
panic(fmt.Sprintf("graph: sema: %s does not exist", id))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sema.V(1); err != nil { // unlock!
|
err := sema.V(1) // unlock!
|
||||||
reterr = multierr.Append(reterr, err) // list of errors
|
reterr = errwrap.Append(reterr, err) // list of errors
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return reterr
|
return reterr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/engine"
|
"github.com/purpleidea/mgmt/engine"
|
||||||
engineUtil "github.com/purpleidea/mgmt/engine/util"
|
engineUtil "github.com/purpleidea/mgmt/engine/util"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendRecv pulls in the sent values into the receive slots. It is called by the
|
// SendRecv pulls in the sent values into the receive slots. It is called by the
|
||||||
@@ -50,25 +48,25 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
|
|
||||||
if st == nil {
|
if st == nil {
|
||||||
e := fmt.Errorf("received nil value from: %s", v.Res)
|
e := fmt.Errorf("received nil value from: %s", v.Res)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if e := engineUtil.StructFieldCompat(st, v.Key, res, k); e != nil {
|
if e := engineUtil.StructFieldCompat(st, v.Key, res, k); e != nil {
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// send
|
// send
|
||||||
m1, e := engineUtil.StructTagToFieldName(st)
|
m1, e := engineUtil.StructTagToFieldName(st)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
key1, exists := m1[v.Key]
|
key1, exists := m1[v.Key]
|
||||||
if !exists {
|
if !exists {
|
||||||
e := fmt.Errorf("requested key of `%s` not found in send struct", v.Key)
|
e := fmt.Errorf("requested key of `%s` not found in send struct", v.Key)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,13 +78,13 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
// recv
|
// recv
|
||||||
m2, e := engineUtil.StructTagToFieldName(res)
|
m2, e := engineUtil.StructTagToFieldName(res)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
key2, exists := m2[k]
|
key2, exists := m2[k]
|
||||||
if !exists {
|
if !exists {
|
||||||
e := fmt.Errorf("requested key of `%s` not found in recv struct", k)
|
e := fmt.Errorf("requested key of `%s` not found in recv struct", k)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +101,7 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
// i think we probably want the same kind, at least for now...
|
// i think we probably want the same kind, at least for now...
|
||||||
if kind1 != kind2 {
|
if kind1 != kind2 {
|
||||||
e := fmt.Errorf("kind mismatch between %s: %s and %s: %s", v.Res, kind1, res, kind2)
|
e := fmt.Errorf("kind mismatch between %s: %s and %s: %s", v.Res, kind1, res, kind2)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,21 +109,21 @@ func (obj *Engine) SendRecv(res engine.RecvableRes) (map[string]bool, error) {
|
|||||||
// FIXME: do we want to relax this for string -> *string ?
|
// FIXME: do we want to relax this for string -> *string ?
|
||||||
if e := TypeCmp(value1, value2); e != nil {
|
if e := TypeCmp(value1, value2); e != nil {
|
||||||
e := errwrap.Wrapf(e, "type mismatch between %s and %s", v.Res, res)
|
e := errwrap.Wrapf(e, "type mismatch between %s and %s", v.Res, res)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we can't set, then well this is pointless!
|
// if we can't set, then well this is pointless!
|
||||||
if !value2.CanSet() {
|
if !value2.CanSet() {
|
||||||
e := fmt.Errorf("can't set %s.%s", res, k)
|
e := fmt.Errorf("can't set %s.%s", res, k)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we can't interface, we can't compare...
|
// if we can't interface, we can't compare...
|
||||||
if !value1.CanInterface() || !value2.CanInterface() {
|
if !value1.CanInterface() || !value2.CanInterface() {
|
||||||
e := fmt.Errorf("can't interface %s.%s", res, k)
|
e := fmt.Errorf("can't interface %s.%s", res, k)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import (
|
|||||||
cwe "github.com/aws/aws-sdk-go/service/cloudwatchevents"
|
cwe "github.com/aws/aws-sdk-go/service/cloudwatchevents"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"github.com/aws/aws-sdk-go/service/sns"
|
"github.com/aws/aws-sdk-go/service/sns"
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -393,17 +392,14 @@ func (obj *AwsEc2Res) Close() error {
|
|||||||
// clean up sns objects created by Init/snsWatch
|
// clean up sns objects created by Init/snsWatch
|
||||||
if obj.snsClient != nil {
|
if obj.snsClient != nil {
|
||||||
// delete the topic and associated subscriptions
|
// delete the topic and associated subscriptions
|
||||||
if err := obj.snsDeleteTopic(obj.snsTopicArn); err != nil {
|
e1 := obj.snsDeleteTopic(obj.snsTopicArn)
|
||||||
errList = multierr.Append(errList, err)
|
errList = errwrap.Append(errList, e1)
|
||||||
}
|
|
||||||
// remove the target
|
// remove the target
|
||||||
if err := obj.cweRemoveTarget(CweTargetID, CweRuleName); err != nil {
|
e2 := obj.cweRemoveTarget(CweTargetID, CweRuleName)
|
||||||
errList = multierr.Append(errList, err)
|
errList = errwrap.Append(errList, e2)
|
||||||
}
|
|
||||||
// delete the cloudwatch rule
|
// delete the cloudwatch rule
|
||||||
if err := obj.cweDeleteRule(CweRuleName); err != nil {
|
e3 := obj.cweDeleteRule(CweRuleName)
|
||||||
errList = multierr.Append(errList, err)
|
errList = errwrap.Append(errList, e3)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return errList
|
return errList
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/engine/traits"
|
"github.com/purpleidea/mgmt/engine/traits"
|
||||||
engineUtil "github.com/purpleidea/mgmt/engine/util"
|
engineUtil "github.com/purpleidea/mgmt/engine/util"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -722,13 +720,7 @@ func (obj *ExecRes) cmdOutputRunner(ctx context.Context, cmd *exec.Cmd) (chan *c
|
|||||||
|
|
||||||
// on EOF, scanner.Err() will be nil
|
// on EOF, scanner.Err() will be nil
|
||||||
reterr := scanner.Err()
|
reterr := scanner.Err()
|
||||||
if err := cmd.Wait(); err != nil { // always run Wait()
|
reterr = errwrap.Append(reterr, cmd.Wait()) // always run Wait()
|
||||||
if reterr != nil {
|
|
||||||
reterr = multierr.Append(reterr, err)
|
|
||||||
} else {
|
|
||||||
reterr = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// send any misc errors we encounter on the channel
|
// send any misc errors we encounter on the channel
|
||||||
if reterr != nil {
|
if reterr != nil {
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
"github.com/purpleidea/mgmt/util/socketset"
|
"github.com/purpleidea/mgmt/util/socketset"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
// XXX: Do NOT use subscribe methods from this lib, as they are racey and
|
// XXX: Do NOT use subscribe methods from this lib, as they are racey and
|
||||||
// do not clean up spawned goroutines. Should be replaced when a suitable
|
// do not clean up spawned goroutines. Should be replaced when a suitable
|
||||||
// alternative is available.
|
// alternative is available.
|
||||||
@@ -179,9 +178,7 @@ func (obj *NetRes) Close() error {
|
|||||||
return fmt.Errorf("socket file should not be the root path")
|
return fmt.Errorf("socket file should not be the root path")
|
||||||
}
|
}
|
||||||
if obj.socketFile != "" { // safety
|
if obj.socketFile != "" { // safety
|
||||||
if err := os.Remove(obj.socketFile); err != nil {
|
errList = errwrap.Append(errList, os.Remove(obj.socketFile))
|
||||||
errList = multierr.Append(errList, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return errList
|
return errList
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
"github.com/godbus/dbus"
|
"github.com/godbus/dbus"
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// global tweaks of verbosity and code path
|
// global tweaks of verbosity and code path
|
||||||
@@ -198,9 +197,8 @@ func (obj *Conn) matchSignal(ch chan *dbus.Signal, path dbus.ObjectPath, iface s
|
|||||||
removeSignals := func() error {
|
removeSignals := func() error {
|
||||||
var errList error
|
var errList error
|
||||||
for i := len(argsList) - 1; i >= 0; i-- { // last in first out
|
for i := len(argsList) - 1; i >= 0; i-- { // last in first out
|
||||||
if call := bus.Call(engineUtil.DBusRemoveMatch, 0, argsList[i]); call.Err != nil {
|
call := bus.Call(engineUtil.DBusRemoveMatch, 0, argsList[i])
|
||||||
errList = multierr.Append(errList, call.Err)
|
errList = errwrap.Append(errList, call.Err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return errList
|
return errList
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cluster represents an mgmt cluster. It uses the instance building blocks to
|
// Cluster represents an mgmt cluster. It uses the instance building blocks to
|
||||||
@@ -83,9 +81,7 @@ func (obj *Cluster) Init() error {
|
|||||||
|
|
||||||
dir: instancePrefix,
|
dir: instancePrefix,
|
||||||
}
|
}
|
||||||
if e := obj.instances[h].Init(); e != nil {
|
err = errwrap.Append(err, obj.instances[h].Init())
|
||||||
err = multierr.Append(err, e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@@ -101,9 +97,7 @@ func (obj *Cluster) Close() error {
|
|||||||
if !exists {
|
if !exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if e := instance.Close(); e != nil {
|
err = errwrap.Append(err, instance.Close())
|
||||||
err = multierr.Append(err, e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !obj.Preserve {
|
if !obj.Preserve {
|
||||||
if obj.dir == "" || obj.dir == "/" {
|
if obj.dir == "" || obj.dir == "/" {
|
||||||
@@ -157,9 +151,7 @@ func (obj *Cluster) Kill() error {
|
|||||||
if !exists {
|
if !exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if e := instance.Kill(); e != nil {
|
err = errwrap.Append(err, instance.Kill())
|
||||||
err = multierr.Append(err, e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -178,9 +170,7 @@ func (obj *Cluster) Quit(ctx context.Context) error {
|
|||||||
if !exists {
|
if !exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if e := instance.Quit(ctx); e != nil {
|
err = errwrap.Append(err, instance.Quit(ctx))
|
||||||
err = multierr.Append(err, e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -198,9 +188,7 @@ func (obj *Cluster) Wait(ctx context.Context) error {
|
|||||||
// TODO: do we want individual waits?
|
// TODO: do we want individual waits?
|
||||||
//ctx, cancel := context.WithTimeout(context.Background(), longTimeout*time.Second)
|
//ctx, cancel := context.WithTimeout(context.Background(), longTimeout*time.Second)
|
||||||
//defer cancel()
|
//defer cancel()
|
||||||
if e := instance.Wait(ctx); e != nil {
|
err = errwrap.Append(err, instance.Wait(ctx))
|
||||||
err = multierr.Append(err, e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/lang/types"
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// State represents the state of a function vertex. This corresponds to an AST
|
// State represents the state of a function vertex. This corresponds to an AST
|
||||||
@@ -167,9 +165,8 @@ func (obj *Engine) Init() error {
|
|||||||
|
|
||||||
obj.state[vertex] = &State{Expr: expr} // store some state!
|
obj.state[vertex] = &State{Expr: expr} // store some state!
|
||||||
|
|
||||||
if e := obj.state[vertex].Init(); e != nil {
|
e := obj.state[vertex].Init()
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err != nil { // usually due to `not found` errors
|
if err != nil { // usually due to `not found` errors
|
||||||
return errwrap.Wrapf(err, "could not load requested funcs")
|
return errwrap.Wrapf(err, "could not load requested funcs")
|
||||||
@@ -201,14 +198,14 @@ func (obj *Engine) Validate() error {
|
|||||||
// duplicate pointers would get closed twice, causing a panic...
|
// duplicate pointers would get closed twice, causing a panic...
|
||||||
if inList(node.handle, ptrs) { // check for duplicate ptrs!
|
if inList(node.handle, ptrs) { // check for duplicate ptrs!
|
||||||
e := fmt.Errorf("vertex `%s` has duplicate ptr", vertex)
|
e := fmt.Errorf("vertex `%s` has duplicate ptr", vertex)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
ptrs = append(ptrs, node.handle)
|
ptrs = append(ptrs, node.handle)
|
||||||
}
|
}
|
||||||
for _, edge := range obj.Graph.Edges() {
|
for _, edge := range obj.Graph.Edges() {
|
||||||
if _, ok := edge.(*Edge); !ok {
|
if _, ok := edge.(*Edge); !ok {
|
||||||
e := fmt.Errorf("edge `%s` was not the correct type", edge)
|
e := fmt.Errorf("edge `%s` was not the correct type", edge)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -220,7 +217,7 @@ func (obj *Engine) Validate() error {
|
|||||||
node := obj.state[vertex]
|
node := obj.state[vertex]
|
||||||
if exp := len(node.handle.Info().Sig.Ord); exp != count {
|
if exp := len(node.handle.Info().Sig.Ord); exp != count {
|
||||||
e := fmt.Errorf("expected %d inputs to `%s`, got %d", exp, node, count)
|
e := fmt.Errorf("expected %d inputs to `%s`, got %d", exp, node, count)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,30 +251,30 @@ func (obj *Engine) Validate() error {
|
|||||||
sig := node2.handle.Info().Sig
|
sig := node2.handle.Info().Sig
|
||||||
if len(sig.Ord) == 0 {
|
if len(sig.Ord) == 0 {
|
||||||
e := fmt.Errorf("no input expected from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
e := fmt.Errorf("no input expected from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if count, exists := expected[node2][arg]; !exists {
|
if count, exists := expected[node2][arg]; !exists {
|
||||||
e := fmt.Errorf("wrong input name from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
e := fmt.Errorf("wrong input name from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
} else if count == 0 {
|
} else if count == 0 {
|
||||||
e := fmt.Errorf("duplicate input from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
e := fmt.Errorf("duplicate input from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
expected[node2][arg]-- // subtract one use
|
expected[node2][arg]-- // subtract one use
|
||||||
|
|
||||||
out := node1.handle.Info().Sig.Out
|
out := node1.handle.Info().Sig.Out
|
||||||
if out == nil {
|
if out == nil {
|
||||||
e := fmt.Errorf("no output possible from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
e := fmt.Errorf("no output possible from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
typ, exists := sig.Map[arg] // key in struct
|
typ, exists := sig.Map[arg] // key in struct
|
||||||
if !exists {
|
if !exists {
|
||||||
// second check of this!
|
// second check of this!
|
||||||
e := fmt.Errorf("wrong input name from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
e := fmt.Errorf("wrong input name from `%s` to `%s` with arg `%s`", node1, node2, arg)
|
||||||
err = multierr.Append(err, errwrap.Wrapf(e, "programming error"))
|
err = errwrap.Append(err, errwrap.Wrapf(e, "programming error"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +284,7 @@ func (obj *Engine) Validate() error {
|
|||||||
// pass (output arg variants)
|
// pass (output arg variants)
|
||||||
} else if typ.Cmp(out) != nil {
|
} else if typ.Cmp(out) != nil {
|
||||||
e := fmt.Errorf("type mismatch from `%s` (%s) to `%s` (%s) with arg `%s`", node1, out, node2, typ, arg)
|
e := fmt.Errorf("type mismatch from `%s` (%s) to `%s` (%s) with arg `%s`", node1, out, node2, typ, arg)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,7 +296,7 @@ func (obj *Engine) Validate() error {
|
|||||||
for arg, count := range m {
|
for arg, count := range m {
|
||||||
if count != 0 { // count should be zero if all were used
|
if count != 0 { // count should be zero if all were used
|
||||||
e := fmt.Errorf("missing input to `%s` on arg `%s`", node, arg)
|
e := fmt.Errorf("missing input to `%s` on arg `%s`", node, arg)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -640,7 +637,7 @@ func (obj *Engine) Close() error {
|
|||||||
if node.init { // did we Init this func?
|
if node.init { // did we Init this func?
|
||||||
if e := node.handle.Close(); e != nil {
|
if e := node.handle.Close(); e != nil {
|
||||||
e := errwrap.Wrapf(e, "problem closing func `%s`", node)
|
e := errwrap.Wrapf(e, "problem closing func `%s`", node)
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/lang/types"
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
"github.com/purpleidea/mgmt/util"
|
"github.com/purpleidea/mgmt/util"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -276,18 +274,12 @@ Loop:
|
|||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
e := errwrap.Wrapf(err, "problem streaming func")
|
e := errwrap.Wrapf(err, "problem streaming func")
|
||||||
if reterr != nil {
|
reterr = errwrap.Append(reterr, e)
|
||||||
reterr = multierr.Append(reterr, e)
|
|
||||||
} else {
|
|
||||||
reterr = e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := handle.Close(); err != nil {
|
if err := handle.Close(); err != nil {
|
||||||
if reterr != nil {
|
err = errwrap.Append(err, reterr)
|
||||||
err = multierr.Append(err, reterr)
|
|
||||||
}
|
|
||||||
return nil, errwrap.Wrapf(err, "problem closing func")
|
return nil, errwrap.Wrapf(err, "problem closing func")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/util"
|
"github.com/purpleidea/mgmt/util"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@@ -502,7 +501,7 @@ func (obj *GAPI) Next() chan gapi.Next {
|
|||||||
// because we should tell the lang obj
|
// because we should tell the lang obj
|
||||||
// to shut down all the running facts.
|
// to shut down all the running facts.
|
||||||
if e := obj.LangClose(); e != nil {
|
if e := obj.LangClose(); e != nil {
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/engine"
|
"github.com/purpleidea/mgmt/engine"
|
||||||
"github.com/purpleidea/mgmt/lang/types"
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Node represents either a Stmt or an Expr. It contains the minimum set of
|
// Node represents either a Stmt or an Expr. It contains the minimum set of
|
||||||
@@ -223,21 +222,21 @@ func (obj *Scope) Merge(scope *Scope) error {
|
|||||||
for _, name := range namedVariables {
|
for _, name := range namedVariables {
|
||||||
if _, exists := obj.Variables[name]; exists {
|
if _, exists := obj.Variables[name]; exists {
|
||||||
e := fmt.Errorf("variable `%s` was overwritten", name)
|
e := fmt.Errorf("variable `%s` was overwritten", name)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
obj.Variables[name] = scope.Variables[name]
|
obj.Variables[name] = scope.Variables[name]
|
||||||
}
|
}
|
||||||
for _, name := range namedFunctions {
|
for _, name := range namedFunctions {
|
||||||
if _, exists := obj.Functions[name]; exists {
|
if _, exists := obj.Functions[name]; exists {
|
||||||
e := fmt.Errorf("function `%s` was overwritten", name)
|
e := fmt.Errorf("function `%s` was overwritten", name)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
obj.Functions[name] = scope.Functions[name]
|
obj.Functions[name] = scope.Functions[name]
|
||||||
}
|
}
|
||||||
for _, name := range namedClasses {
|
for _, name := range namedClasses {
|
||||||
if _, exists := obj.Classes[name]; exists {
|
if _, exists := obj.Classes[name]; exists {
|
||||||
e := fmt.Errorf("class `%s` was overwritten", name)
|
e := fmt.Errorf("class `%s` was overwritten", name)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
}
|
}
|
||||||
obj.Classes[name] = scope.Classes[name]
|
obj.Classes[name] = scope.Classes[name]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/util"
|
"github.com/purpleidea/mgmt/util"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -142,9 +141,8 @@ func runInterpret(t *testing.T, code string) (*pgraph.Graph, error) {
|
|||||||
graph, err := lang.Interpret()
|
graph, err := lang.Interpret()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := errwrap.Wrapf(err, "interpret failed")
|
err := errwrap.Wrapf(err, "interpret failed")
|
||||||
if e := closeFn(); e != nil {
|
e := closeFn()
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
}
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Basic types defined here as a convenience for use with Type.Cmp(X).
|
// Basic types defined here as a convenience for use with Type.Cmp(X).
|
||||||
@@ -597,7 +597,7 @@ func (obj *Type) Cmp(typ *Type) error {
|
|||||||
kerr := obj.Key.Cmp(typ.Key)
|
kerr := obj.Key.Cmp(typ.Key)
|
||||||
verr := obj.Val.Cmp(typ.Val)
|
verr := obj.Val.Cmp(typ.Val)
|
||||||
if kerr != nil && verr != nil {
|
if kerr != nil && verr != nil {
|
||||||
return multierr.Append(kerr, verr) // two errors
|
return errwrap.Append(kerr, verr) // two errors
|
||||||
}
|
}
|
||||||
if kerr != nil {
|
if kerr != nil {
|
||||||
return kerr
|
return kerr
|
||||||
@@ -964,7 +964,7 @@ func (obj *Type) ComplexCmp(typ *Type) (string, error) {
|
|||||||
kstatus, kerr := obj.Key.ComplexCmp(typ.Key)
|
kstatus, kerr := obj.Key.ComplexCmp(typ.Key)
|
||||||
vstatus, verr := obj.Val.ComplexCmp(typ.Val)
|
vstatus, verr := obj.Val.ComplexCmp(typ.Val)
|
||||||
if kerr != nil && verr != nil {
|
if kerr != nil && verr != nil {
|
||||||
return "", multierr.Append(kerr, verr) // two errors
|
return "", errwrap.Append(kerr, verr) // two errors
|
||||||
}
|
}
|
||||||
if kerr != nil {
|
if kerr != nil {
|
||||||
return "", kerr
|
return "", kerr
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/puppet"
|
"github.com/purpleidea/mgmt/puppet"
|
||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -329,12 +328,11 @@ func (obj *GAPI) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if e := obj.langGAPI.Close(); e != nil {
|
e1 := obj.langGAPI.Close()
|
||||||
err = multierr.Append(err, errwrap.Wrapf(e, "closing lang GAPI failed"))
|
err = errwrap.Append(err, errwrap.Wrapf(e1, "closing lang GAPI failed"))
|
||||||
}
|
|
||||||
if e := obj.puppetGAPI.Close(); e != nil {
|
e2 := obj.puppetGAPI.Close()
|
||||||
err = multierr.Append(err, errwrap.Wrapf(e, "closing Puppet GAPI failed"))
|
err = errwrap.Append(err, errwrap.Wrapf(e2, "closing Puppet GAPI failed"))
|
||||||
}
|
|
||||||
|
|
||||||
close(obj.closeChan)
|
close(obj.closeChan)
|
||||||
obj.initialized = false // closed = true
|
obj.initialized = false // closed = true
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/util/errwrap"
|
"github.com/purpleidea/mgmt/util/errwrap"
|
||||||
|
|
||||||
etcdtypes "github.com/coreos/etcd/pkg/types"
|
etcdtypes "github.com/coreos/etcd/pkg/types"
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags are some constant flags which are used throughout the program.
|
// Flags are some constant flags which are used throughout the program.
|
||||||
@@ -575,7 +574,7 @@ func (obj *Main) Run() error {
|
|||||||
res, ok := v.(engine.Res)
|
res, ok := v.(engine.Res)
|
||||||
if !ok {
|
if !ok {
|
||||||
e := fmt.Errorf("vertex `%s` is not a Res", v)
|
e := fmt.Errorf("vertex `%s` is not a Res", v)
|
||||||
err = multierr.Append(err, e)
|
err = errwrap.Append(err, e)
|
||||||
continue // we'll catch the error later!
|
continue // we'll catch the error later!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -847,9 +846,8 @@ func (obj *Main) Close() error {
|
|||||||
// run cleanup functions in reverse (defer) order
|
// run cleanup functions in reverse (defer) order
|
||||||
for i := len(obj.cleanup) - 1; i >= 0; i-- {
|
for i := len(obj.cleanup) - 1; i >= 0; i-- {
|
||||||
fn := obj.cleanup[i]
|
fn := obj.cleanup[i]
|
||||||
if e := fn(); e != nil {
|
e := fn()
|
||||||
err = multierr.Append(err, e) // list of errors
|
err = errwrap.Append(err, e) // list of errors
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ function consistent-imports() {
|
|||||||
if grep $'\t"github.com/pkg/errors"' "$1"; then
|
if grep $'\t"github.com/pkg/errors"' "$1"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if grep $'\t"github.com/hashicorp/go-multierror"' "$1"; then # import as multierr
|
# import as github.com/purpleidea/mgmt/util/errwrap
|
||||||
|
if grep $'\t"github.com/hashicorp/go-multierror"' "$1"; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if grep $'\t"github.com/purpleidea/mgmt/engine/util"' "$1"; then # import as engineUtil
|
if grep $'\t"github.com/purpleidea/mgmt/engine/util"' "$1"; then # import as engineUtil
|
||||||
|
|||||||
Reference in New Issue
Block a user