Skip to content

Commit

Permalink
Add some error checking on the parsed data fields
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Oct 30, 2020
1 parent be770af commit e1effd3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func ParseMemFree(out string) (int64, int64, error) {
l := len(outlines)
for _, line := range outlines[1 : l-1] {
parsedLine := strings.Fields(line)
if len(parsedLine) < 7 {
continue
}
t, err := strconv.ParseInt(parsedLine[1], 10, 64)
if err != nil {
return 0, 0, err
Expand All @@ -86,7 +89,7 @@ func ParseMemFree(out string) (int64, int64, error) {
return t, a, nil
}
}
return 0, 0, nil
return 0, 0, errors.New("No matching data found")
}

// ParseDiskFree parses the output of the `df -m` command
Expand All @@ -98,6 +101,9 @@ func ParseDiskFree(out string) (int64, int64, error) {
l := len(outlines)
for _, line := range outlines[1 : l-1] {
parsedLine := strings.Fields(line)
if len(parsedLine) < 6 {
continue
}
t, err := strconv.ParseInt(parsedLine[1], 10, 64)
if err != nil {
return 0, 0, err
Expand All @@ -111,7 +117,7 @@ func ParseDiskFree(out string) (int64, int64, error) {
return t, a, nil
}
}
return 0, 0, nil
return 0, 0, errors.New("No matching data found")
}

// GetBinaryDownloadURL returns a suitable URL for the platform
Expand Down

0 comments on commit e1effd3

Please sign in to comment.