From 6b8ed19f09439a1d8af9129143ebf96a4c3b8774 Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sun, 21 Feb 2016 16:00:31 -0500 Subject: Implemented error catching on GetAllLights if no lights are found. --- bridge.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bridge.go') diff --git a/bridge.go b/bridge.go index 6b781c1..f78b8e3 100644 --- a/bridge.go +++ b/bridge.go @@ -221,10 +221,15 @@ func (bridge *Bridge) GetAllLights() ([]Light, error) { for index := 1; index < 101; index++ { light, err := bridge.GetLightByIndex(index) if err != nil { - break + break // Final light index reached, index does not exist. } lights = append(lights, light) } + if len(lights) == 0 { + err := errors.New("Error: No lights found by GetAllLights.") + log.Println(err) + return lights, err + } return lights, nil } -- cgit v1.2.3