Add error handling for bad UPS IDs

This commit is contained in:
2025-10-18 16:53:53 -04:00
parent e15cb96069
commit 42b80c18ad
+5 -1
View File
@@ -78,7 +78,11 @@ func (c *Client) GetVar(upsID, varName string) (string, error) {
if err != nil {
return "", err
}
value := strings.Trim(strings.Join(strings.Split(l, " ")[3:], " "), "\"")
lSplit := strings.Split(l, " ")
if len(lSplit) < 4 {
return "", fmt.Errorf("invalid response to GET VAR; check your UPS ID")
}
value := strings.Trim(strings.Join(lSplit[3:], " "), "\"")
return value, nil
}