From d983bfb9a384752f8937e2df4327add293c96daa Mon Sep 17 00:00:00 2001 From: finn Date: Thu, 29 Dec 2022 17:45:22 -0800 Subject: [PATCH] improve error handling for listen --- signald/signald.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/signald/signald.go b/signald/signald.go index f790d0c..e82ccca 100644 --- a/signald/signald.go +++ b/signald/signald.go @@ -104,7 +104,7 @@ func (s *Signald) Close() error { } // Listen listens for events from signald -func (s *Signald) Listen(c chan client_protocol.BasicResponse) { +func (s *Signald) Listen(c chan client_protocol.BasicResponse) error { for { msg, err := s.readNext() if err == io.EOF { @@ -112,7 +112,11 @@ func (s *Signald) Listen(c chan client_protocol.BasicResponse) { if c != nil { close(c) } - return + return nil + } + + if err != nil { + return err } if msg.Type == "unexpected_error" { @@ -174,9 +178,6 @@ func (s *Signald) readNext() (b client_protocol.BasicResponse, err error) { } else { err = json.NewDecoder(s.socket).Decode(&b) } - if err != nil { - log.Println("signald-go: error decoding message from signald:", err) - return - } + return }