Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAPPL-402] correctly propagate errors on fetcher #15758

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/services/workflows/syncer/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,9 @@ func (s *FetcherService) Fetch(ctx context.Context, url string) ([]byte, error)
return nil, err
}

if payload.ExecutionError {
return nil, fmt.Errorf("execution error from gateway: %s", payload.ErrorMessage)
}

return payload.Body, nil
}
34 changes: 34 additions & 0 deletions core/services/workflows/syncer/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,40 @@ func TestNewFetcherService(t *testing.T) {
expectedPayload := []byte("response body")
require.Equal(t, expectedPayload, payload)
})

t.Run("NOK-response_payload_too_large", func(t *testing.T) {
headers := map[string]string{"Content-Type": "application/json"}
responsePayload, err := json.Marshal(ghcapabilities.Response{
StatusCode: 400,
Headers: headers,
ErrorMessage: "http: request body too large",
ExecutionError: true,
})
require.NoError(t, err)
gatewayResponse := &api.Message{
Body: api.MessageBody{
MessageId: msgID,
Method: ghcapabilities.MethodWebAPITarget,
Payload: responsePayload,
},
}

connector.EXPECT().AddHandler([]string{capabilities.MethodWorkflowSyncer}, mock.Anything).Return(nil)

fetcher := NewFetcherService(lggr, wrapper)
require.NoError(t, fetcher.Start(ctx))
defer fetcher.Close()

connector.EXPECT().SignAndSendToGateway(mock.Anything, "gateway1", mock.Anything).Run(func(ctx context.Context, gatewayID string, msg *api.MessageBody) {
fetcher.och.HandleGatewayMessage(ctx, "gateway1", gatewayResponse)
}).Return(nil).Times(1)
connector.EXPECT().DonID().Return("don-id")
connector.EXPECT().AwaitConnection(matches.AnyContext, "gateway1").Return(nil)
connector.EXPECT().GatewayIDs().Return([]string{"gateway1", "gateway2"})

_, err = fetcher.Fetch(ctx, url)
require.Error(t, err, "execution error from gateway: http: request body too large")
})
}

func gatewayResponse(t *testing.T, msgID string) *api.Message {
Expand Down
6 changes: 3 additions & 3 deletions core/services/workflows/syncer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,19 @@ func (h *eventHandler) getWorkflowArtifacts(
if err != nil {
binary, err2 := h.fetcher(ctx, payload.BinaryURL)
if err2 != nil {
return nil, nil, fmt.Errorf("failed to fetch binary from %s : %w", payload.BinaryURL, err)
return nil, nil, fmt.Errorf("failed to fetch binary from %s : %w", payload.BinaryURL, err2)
}

decodedBinary, err2 := base64.StdEncoding.DecodeString(string(binary))
if err2 != nil {
return nil, nil, fmt.Errorf("failed to decode binary: %w", err)
return nil, nil, fmt.Errorf("failed to decode binary: %w", err2)
}

var config []byte
if payload.ConfigURL != "" {
config, err2 = h.fetcher(ctx, payload.ConfigURL)
if err2 != nil {
return nil, nil, fmt.Errorf("failed to fetch config from %s : %w", payload.ConfigURL, err)
return nil, nil, fmt.Errorf("failed to fetch config from %s : %w", payload.ConfigURL, err2)
}
}
return decodedBinary, config, nil
Expand Down
Loading