17170: Improve error messages.
authorTom Clegg <tom@curii.com>
Thu, 14 Jan 2021 20:40:07 +0000 (15:40 -0500)
committerTom Clegg <tom@curii.com>
Thu, 14 Jan 2021 21:19:33 +0000 (16:19 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/controller/localdb/container_gateway.go
lib/crunchrun/container_gateway.go

index f255bff842cb3c29f2b5fa6f67d4f72732606c63..807995b3c5a2dc0f9f2eb4797f4ee1df2d071870 100644 (file)
@@ -55,12 +55,17 @@ func (conn *Conn) ContainerSSH(ctx context.Context, opts arvados.ContainerSSHOpt
                return
        }
 
-       ctr, err := conn.railsProxy.ContainerGet(ctx, arvados.GetOptions{UUID: opts.UUID})
-       if err != nil {
+       switch ctr.State {
+       case arvados.ContainerStateQueued, arvados.ContainerStateLocked:
+               err = httpserver.ErrorWithStatus(fmt.Errorf("gateway is not available, container is %s", strings.ToLower(string(ctr.State))), http.StatusServiceUnavailable)
                return
-       }
-       if ctr.GatewayAddress == "" || ctr.State != arvados.ContainerStateRunning {
-               err = httpserver.ErrorWithStatus(fmt.Errorf("gateway is not available, container is %s", strings.ToLower(string(ctr.State))), http.StatusBadGateway)
+       case arvados.ContainerStateRunning:
+               if ctr.GatewayAddress == "" {
+                       err = httpserver.ErrorWithStatus(errors.New("container is running but gateway is not available"), http.StatusServiceUnavailable)
+                       return
+               }
+       default:
+               err = httpserver.ErrorWithStatus(fmt.Errorf("gateway is not available, container is %s", strings.ToLower(string(ctr.State))), http.StatusGone)
                return
        }
        // crunch-run uses a self-signed / unverifiable TLS
@@ -101,6 +106,7 @@ func (conn *Conn) ContainerSSH(ctx context.Context, opts arvados.ContainerSSHOpt
                },
        })
        if err != nil {
+               err = httpserver.ErrorWithStatus(err, http.StatusBadGateway)
                return
        }
        if respondAuth == "" {
index 0d869ca7fc750f4969c5f423245dc1c860124b7d..3764a8a439690d7e94da59eaa8e686a70a18598c 100644 (file)
@@ -194,7 +194,7 @@ func (gw *Gateway) handleSSH(w http.ResponseWriter, req *http.Request) {
        go ssh.DiscardRequests(reqs)
        for newch := range newchans {
                if newch.ChannelType() != "session" {
-                       newch.Reject(ssh.UnknownChannelType, "unknown channel type")
+                       newch.Reject(ssh.UnknownChannelType, fmt.Sprintf("unsupported channel type %q", newch.ChannelType()))
                        continue
                }
                ch, reqs, err := newch.Accept()