17170: Improve error messages.
authorTom Clegg <tom@curii.com>
Wed, 13 Jan 2021 22:17:50 +0000 (17:17 -0500)
committerTom Clegg <tom@curii.com>
Wed, 13 Jan 2021 22:17:50 +0000 (17:17 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/controller/rpc/conn.go

index 48e67e2742717eb0f53f8616196730763e6f67c8..a9a638759e623ee04a9cb362259f77bb6899afc6 100644 (file)
@@ -313,6 +313,7 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
 
        u, err := conn.baseURL.Parse("/" + strings.Replace(arvados.EndpointContainerSSH.Path, "{uuid}", options.UUID, -1))
        if err != nil {
+               err = fmt.Errorf("tls.Dial: %w", err)
                return
        }
        u.RawQuery = url.Values{
@@ -334,12 +335,20 @@ func (conn *Conn) ContainerSSH(ctx context.Context, options arvados.ContainerSSH
        bufw.Flush()
        resp, err := http.ReadResponse(bufr, &http.Request{Method: "GET"})
        if err != nil {
+               err = fmt.Errorf("http.ReadResponse: %w", err)
                return
        }
        if resp.StatusCode != http.StatusSwitchingProtocols {
                defer resp.Body.Close()
                body, _ := ioutil.ReadAll(resp.Body)
-               err = fmt.Errorf("server did not provide a tunnel: %d %q", resp.StatusCode, body)
+               var message string
+               var errDoc httpserver.ErrorResponse
+               if err := json.Unmarshal(body, &errDoc); err != nil {
+                       message = strings.Join(errDoc.Errors, "; ")
+               } else {
+                       message = fmt.Sprintf("%q", body)
+               }
+               err = fmt.Errorf("server did not provide a tunnel: %q (HTTP %d)", message, resp.StatusCode)
                return
        }
        if strings.ToLower(resp.Header.Get("Upgrade")) != "ssh" ||