From 452fbd0bf14678f1ceb8e60a8864693e062b89b6 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 14 Jan 2021 15:40:07 -0500 Subject: [PATCH] 17170: Improve error messages. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/controller/localdb/container_gateway.go | 16 +++++++++++----- lib/crunchrun/container_gateway.go | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/controller/localdb/container_gateway.go b/lib/controller/localdb/container_gateway.go index f255bff842..807995b3c5 100644 --- a/lib/controller/localdb/container_gateway.go +++ b/lib/controller/localdb/container_gateway.go @@ -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 == "" { diff --git a/lib/crunchrun/container_gateway.go b/lib/crunchrun/container_gateway.go index 0d869ca7fc..3764a8a439 100644 --- a/lib/crunchrun/container_gateway.go +++ b/lib/crunchrun/container_gateway.go @@ -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() -- 2.30.2