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

Commit

Permalink
clh: Add some error handling for clh
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
amshinde committed Aug 21, 2020
1 parent e75299c commit c87ff44
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,12 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
clhPath, err := clh.clhPath()
if err != nil {
return err

}

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

words := strings.Fields(string(out))
Expand All @@ -860,23 +859,22 @@ func (clh *cloudHypervisor) getAvailableVersion() error {
versionSplit[0] = strings.TrimLeft(versionSplit[0], "v")
major, err := strconv.ParseUint(versionSplit[0], 10, 64)
if err != nil {
return err

return fmt.Errorf("Failed to parse cloud-hypervisor version: %v, Unexpected format", words)
}
minor, err := strconv.ParseUint(versionSplit[1], 10, 64)
if err != nil {
return err
return fmt.Errorf("Failed to parse cloud-hypervisor version: %v, Unexpected format", words)

}

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

clh.version = CloudHypervisorVersion{
Expand Down

0 comments on commit c87ff44

Please sign in to comment.