Skip to content

Commit

Permalink
[Keystone] Standard error message for remote execution errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bolekk committed Dec 10, 2024
1 parent 9d8d9f4 commit e47443a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions core/capabilities/remote/executable/request/server_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package request

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -48,6 +49,8 @@ type ServerRequest struct {
lggr logger.Logger
}

var externalErrorMsg = errors.New("failed to execute capability")

Check failure on line 52 in core/capabilities/remote/executable/request/server_request.go

View workflow job for this annotation

GitHub Actions / lint

error-naming: error var externalErrorMsg should have name of the form errFoo (revive)

func NewServerRequest(capability capabilities.ExecutableCapability, method string, capabilityID string, capabilityDonID uint32,
capabilityPeerID p2ptypes.PeerID,
callingDon commoncap.DON, requestID string,
Expand Down Expand Up @@ -228,20 +231,22 @@ func executeCapabilityRequest(ctx context.Context, lggr logger.Logger, capabilit
payload []byte) ([]byte, error) {
capabilityRequest, err := pb.UnmarshalCapabilityRequest(payload)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal capability request: %w", err)
lggr.Errorw("failed to unmarshal capability request", "err", err)
return nil, externalErrorMsg
}

lggr.Debugw("executing capability", "metadata", capabilityRequest.Metadata)
capResponse, err := capability.Execute(ctx, capabilityRequest)

if err != nil {
lggr.Debugw("received execution error", "workflowExecutionID", capabilityRequest.Metadata.WorkflowExecutionID, "error", err)
return nil, fmt.Errorf("failed to execute capability: %w", err)
lggr.Errorw("received execution error", "workflowExecutionID", capabilityRequest.Metadata.WorkflowExecutionID, "error", err)
return nil, externalErrorMsg
}

responsePayload, err := pb.MarshalCapabilityResponse(capResponse)
if err != nil {
return nil, fmt.Errorf("failed to marshal capability response: %w", err)
lggr.Errorw("failed to marshal capability request", "err", err)
return nil, externalErrorMsg
}

lggr.Debugw("received execution results", "workflowExecutionID", capabilityRequest.Metadata.WorkflowExecutionID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func Test_ServerRequest_MessageValidation(t *testing.T) {
require.NoError(t, err)
assert.Len(t, dispatcher.msgs, 2)
assert.Equal(t, types.Error_INTERNAL_ERROR, dispatcher.msgs[0].Error)
assert.Equal(t, "failed to execute capability: an error", dispatcher.msgs[0].ErrorMsg)
assert.Equal(t, "failed to execute capability", dispatcher.msgs[0].ErrorMsg)
assert.Equal(t, types.Error_INTERNAL_ERROR, dispatcher.msgs[1].Error)
assert.Equal(t, "failed to execute capability: an error", dispatcher.msgs[1].ErrorMsg)
assert.Equal(t, "failed to execute capability", dispatcher.msgs[1].ErrorMsg)
})

t.Run("Execute capability", func(t *testing.T) {
Expand Down

0 comments on commit e47443a

Please sign in to comment.