From 9c3658737c5d1cddbd0e0faac2cab856ce1de4bb Mon Sep 17 00:00:00 2001 From: Bolek <1416262+bolekk@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:54:24 -0800 Subject: [PATCH] [Keystone] Standard error message for remote execution errors (#15615) --- .../capabilities/remote/executable/endtoend_test.go | 6 +++--- .../remote/executable/request/server_request.go | 13 +++++++++---- .../executable/request/server_request_test.go | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/capabilities/remote/executable/endtoend_test.go b/core/capabilities/remote/executable/endtoend_test.go index 8be92e878ad..5f445db4235 100644 --- a/core/capabilities/remote/executable/endtoend_test.go +++ b/core/capabilities/remote/executable/endtoend_test.go @@ -78,7 +78,7 @@ func Test_RemoteExecutionCapability_CapabilityError(t *testing.T) { methods = append(methods, func(ctx context.Context, caller commoncap.ExecutableCapability) { executeCapability(ctx, t, caller, transmissionSchedule, func(t *testing.T, responseCh commoncap.CapabilityResponse, responseError error) { - assert.Equal(t, "error executing request: failed to execute capability: an error", responseError.Error()) + assert.Equal(t, "error executing request: failed to execute capability", responseError.Error()) }) }) @@ -102,12 +102,12 @@ func Test_RemoteExecutableCapability_RandomCapabilityError(t *testing.T) { methods = append(methods, func(ctx context.Context, caller commoncap.ExecutableCapability) { executeCapability(ctx, t, caller, transmissionSchedule, func(t *testing.T, responseCh commoncap.CapabilityResponse, responseError error) { - assert.Equal(t, "error executing request: request expired by executable client", responseError.Error()) + assert.Equal(t, "error executing request: failed to execute capability", responseError.Error()) }) }) for _, method := range methods { - testRemoteExecutableCapability(ctx, t, capability, 10, 9, 10*time.Millisecond, 10, 9, 10*time.Minute, + testRemoteExecutableCapability(ctx, t, capability, 10, 9, 1*time.Second, 10, 9, 10*time.Minute, method) } } diff --git a/core/capabilities/remote/executable/request/server_request.go b/core/capabilities/remote/executable/request/server_request.go index a4662e93987..629622494a4 100644 --- a/core/capabilities/remote/executable/request/server_request.go +++ b/core/capabilities/remote/executable/request/server_request.go @@ -2,6 +2,7 @@ package request import ( "context" + "errors" "fmt" "sync" "time" @@ -48,6 +49,8 @@ type ServerRequest struct { lggr logger.Logger } +var errExternalErrorMsg = errors.New("failed to execute capability") + func NewServerRequest(capability capabilities.ExecutableCapability, method string, capabilityID string, capabilityDonID uint32, capabilityPeerID p2ptypes.PeerID, callingDon commoncap.DON, requestID string, @@ -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, errExternalErrorMsg } 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, errExternalErrorMsg } 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, errExternalErrorMsg } lggr.Debugw("received execution results", "workflowExecutionID", capabilityRequest.Metadata.WorkflowExecutionID) diff --git a/core/capabilities/remote/executable/request/server_request_test.go b/core/capabilities/remote/executable/request/server_request_test.go index cbeec833a1f..ce539154d93 100644 --- a/core/capabilities/remote/executable/request/server_request_test.go +++ b/core/capabilities/remote/executable/request/server_request_test.go @@ -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) {