From ebbbfdb9befe98062276f4f815dc6465b7435ea5 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 10 Dec 2021 10:01:31 +0100 Subject: [PATCH] Unwrap Nomad error for allocation exec * This will allow us to inspect whether the websocket connection was closed normally --- internal/nomad/api_querier.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/nomad/api_querier.go b/internal/nomad/api_querier.go index 66b9718..0d8061d 100644 --- a/internal/nomad/api_querier.go +++ b/internal/nomad/api_querier.go @@ -100,11 +100,14 @@ func (nc *nomadAPIClient) Execute(runnerID string, return 1, fmt.Errorf("error retrieving allocation info: %w", err) } exitCode, err := nc.client.Allocations().Exec(ctx, allocation, TaskName, tty, command, stdin, stdout, stderr, nil, nil) - if err != nil && websocket.IsCloseError(err, websocket.CloseNormalClosure) { - log.WithError(err).Info("The exit code could not be received.") - return 0, nil - } else if err != nil { - return 1, fmt.Errorf("error executing command in allocation: %w", err) + if err != nil { + rootCause := errors.Unwrap(err) + if rootCause != nil && websocket.IsCloseError(rootCause, websocket.CloseNormalClosure) { + log.WithError(err).Info("The exit code could not be received.") + return 0, nil + } else { + return 1, fmt.Errorf("error executing command in allocation: %w", err) + } } return exitCode, nil }