Merge pull request #71 from openHPI/fix/#44-unwrapping-error
Unwrap Nomad Error for Allocation Exec
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
18
internal/nomad/api_querier_test.go
Normal file
18
internal/nomad/api_querier_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package nomad
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWebsocketErrorNeedsToBeUnwrapped(t *testing.T) {
|
||||
rawError := &websocket.CloseError{Code: websocket.CloseNormalClosure}
|
||||
err := fmt.Errorf("websocket closed before receiving exit code: %w", rawError)
|
||||
|
||||
assert.False(t, websocket.IsCloseError(err, websocket.CloseNormalClosure))
|
||||
rootCause := errors.Unwrap(err)
|
||||
assert.True(t, websocket.IsCloseError(rootCause, websocket.CloseNormalClosure))
|
||||
}
|
Reference in New Issue
Block a user