Skip to content

Commit

Permalink
xcli error enhancements
Browse files Browse the repository at this point in the history
This patch makes the executor binary emit more detailed error messages
to the stderr when they are encountered. It also modifies the libStorage
client to log the stderr of the lsx command when it sees an error.
  • Loading branch information
codenrhoden committed Apr 7, 2017
1 parent 7e239b5 commit 2bb0fb2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 11 additions & 1 deletion cli/lsx/lsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"
"time"

"github.com/akutz/goof"

"github.com/codedellemc/libstorage/api/context"
"github.com/codedellemc/libstorage/api/registry"
apitypes "github.com/codedellemc/libstorage/api/types"
Expand Down Expand Up @@ -270,8 +272,16 @@ func Run() {
if strings.EqualFold(err.Error(), apitypes.ErrNotImplemented.Error()) {
exitCode = apitypes.LSXExitCodeNotImplemented
}
var errStr string
switch e := err.(type) {
case goof.Goof:
e.IncludeFieldsInError(true)
errStr = e.Error()
default:
errStr = e.Error()
}
fmt.Fprintf(os.Stderr,
"error: error getting %s: %v\n", op, err)
"error: error getting %s: %v\n", op, errStr)
os.Exit(exitCode)
}

Expand Down
11 changes: 9 additions & 2 deletions drivers/storage/libstorage/libstorage_client_xcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,17 @@ func (c *client) runExecutor(
case types.LSXExitCodeTimedOut:
return nil, types.ErrTimedOut
}
stderr := string(exitError.Stderr)
ctx.WithFields(log.Fields{
"cmd": lsxBin,
"args": args,
"stderr": stderr,
}).Error("error from executor cli")
return nil, goof.WithFieldsE(
map[string]interface{}{
"lsx": lsxBin,
"args": args,
"lsx": lsxBin,
"args": args,
"stderr": stderr,
},
"error executing xcli",
err)
Expand Down
6 changes: 5 additions & 1 deletion drivers/storage/rbd/executor/rbd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ func GetInstanceID(
func getCephMonIPs() ([]net.IP, error) {
out, err := exec.Command("ceph-conf", "--lookup", "mon_host").Output()
if err != nil {
return nil, goof.WithError("Unable to get Ceph monitors", err)
if exiterr, ok := err.(*exec.ExitError); ok {
return nil, goof.WithField("stderr", string(exiterr.Stderr),
"unable to get Ceph monitors")
}
return nil, goof.WithError("unable to get Ceph monitors", err)
}

monStrings := strings.Split(strings.TrimSpace(string(out)), ",")
Expand Down

0 comments on commit 2bb0fb2

Please sign in to comment.