]> git.giacomolli.uk - onechat/blobdiff - terminal.go
Check operation context on returned errors
[onechat] / terminal.go
index 876986a4479f38a679d9d2dc586be8a85164ac15..eff009cd9f7e225f45e96b72f8e72e3f79f20eca 100644 (file)
@@ -71,7 +71,11 @@ func terminalSession(ctx context.Context, conn net.Conn, in io.Reader, out io.Wr
                <-shown
        }
 
                <-shown
        }
 
-       return err
+       if err != nil {
+               return fmt.Errorf("run terminal client: %w", err)
+       }
+
+       return nil
 }
 
 // terminalSendLines sends each line of in as a request until the input ends.
 }
 
 // terminalSendLines sends each line of in as a request until the input ends.
@@ -113,7 +117,12 @@ func terminalSendLines(ctx context.Context, conn net.Conn, in io.Reader) error {
                }
        }
 
                }
        }
 
-       return scanner.Err()
+       err := scanner.Err()
+       if err != nil {
+               return fmt.Errorf("read terminal input: %w", err)
+       }
+
+       return nil
 }
 
 // terminalShowEvents writes each event from the daemon to out until the
 }
 
 // terminalShowEvents writes each event from the daemon to out until the
@@ -135,11 +144,16 @@ func terminalShowEvents(conn net.Conn, out io.Writer) error {
 
                _, err = io.WriteString(out, text+"\n")
                if err != nil {
 
                _, err = io.WriteString(out, text+"\n")
                if err != nil {
-                       return err
+                       return fmt.Errorf("write terminal event: %w", err)
                }
        }
 
                }
        }
 
-       return scanner.Err()
+       err := scanner.Err()
+       if err != nil {
+               return fmt.Errorf("read daemon events: %w", err)
+       }
+
+       return nil
 }
 
 // terminalCmpError returns err, or fallback when err is nil.
 }
 
 // terminalCmpError returns err, or fallback when err is nil.