Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit c87ff44

Browse files
committed
clh: Add some error handling for clh
The function for getting version info was failing on a system without any indication of the error. Add some error handling around this function. Fixes: github.com/kata-containers/kata-containers#463 Signed-off-by: Archana Shinde <[email protected]>
1 parent e75299c commit c87ff44

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

virtcontainers/clh.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,12 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
836836
clhPath, err := clh.clhPath()
837837
if err != nil {
838838
return err
839-
840839
}
841840

842841
cmd := exec.Command(clhPath, "--version")
843842
out, err := cmd.CombinedOutput()
844843
if err != nil {
845-
return err
844+
return fmt.Errorf("Could not retrieve cloud-hypervisor version, binary returned error: %s", err)
846845
}
847846

848847
words := strings.Fields(string(out))
@@ -860,23 +859,22 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
860859
versionSplit[0] = strings.TrimLeft(versionSplit[0], "v")
861860
major, err := strconv.ParseUint(versionSplit[0], 10, 64)
862861
if err != nil {
863-
return err
864-
862+
return fmt.Errorf("Failed to parse cloud-hypervisor version: %v, Unexpected format", words)
865863
}
866864
minor, err := strconv.ParseUint(versionSplit[1], 10, 64)
867865
if err != nil {
868-
return err
866+
return fmt.Errorf("Failed to parse cloud-hypervisor version: %v, Unexpected format", words)
869867

870868
}
871869

872870
// revision could have aditional commit information separated by '-'
873871
revisionSplit := strings.SplitN(versionSplit[2], "-", -1)
874872
if len(revisionSplit) < 1 {
875-
return errors.Errorf("Failed parse cloud-hypervisor revision %s", versionSplit[2])
873+
return errors.Errorf("Failed parse cloud-hypervisor revision %v", words)
876874
}
877875
revision, err := strconv.ParseUint(revisionSplit[0], 10, 64)
878876
if err != nil {
879-
return err
877+
return fmt.Errorf("Failed to parse cloud-hypervisor version, Unexpected revision format: %v", words)
880878
}
881879

882880
clh.version = CloudHypervisorVersion{

0 commit comments

Comments
 (0)