From 42b80c18adf6186404256304223d438d20e5770a Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 18 Oct 2025 16:53:53 -0400 Subject: [PATCH] Add error handling for bad UPS IDs --- nut.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nut.go b/nut.go index 6de6715..8bb8f89 100644 --- a/nut.go +++ b/nut.go @@ -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 }