Print a better error when virtualbox fails

Instead of printing `exit status 1` we'll print
the stderr output

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-10-27 15:22:38 +01:00
parent 9fa2f73139
commit d316eb7e96
1 changed files with 6 additions and 2 deletions

View File

@ -61,17 +61,21 @@ func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {
log.Debugf("STDOUT:\n{\n%v}", stdout.String()) log.Debugf("STDOUT:\n{\n%v}", stdout.String())
log.Debugf("STDERR:\n{\n%v}", stderrStr) log.Debugf("STDERR:\n{\n%v}", stderrStr)
} }
if err != nil { if err != nil {
if ee, ok := err.(*exec.Error); ok && ee.Err == exec.ErrNotFound { if ee, ok := err.(*exec.Error); ok && ee.Err == exec.ErrNotFound {
err = ErrVBMNotFound err = ErrVBMNotFound
} }
} else { }
if err == nil || strings.HasPrefix(err.Error(), "exit status ") {
// VBoxManage will sometimes not set the return code, but has a fatal error // VBoxManage will sometimes not set the return code, but has a fatal error
// such as VBoxManage.exe: error: VT-x is not available. (VERR_VMX_NO_VMX) // such as VBoxManage.exe: error: VT-x is not available. (VERR_VMX_NO_VMX)
if strings.Contains(stderrStr, "error:") { if strings.Contains(stderrStr, "error:") {
err = fmt.Errorf("%v %v failed: %v", vboxManageCmd, strings.Join(args, " "), stderrStr) err = fmt.Errorf("%v %v failed:\n%v", vboxManageCmd, strings.Join(args, " "), stderrStr)
} }
} }
return stdout.String(), stderrStr, err return stdout.String(), stderrStr, err
} }