Skip to content

Commit

Permalink
Fixed last test
Browse files Browse the repository at this point in the history
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
  • Loading branch information
ItalyPaleAle committed Dec 15, 2023
1 parent 96056ee commit f8d0517
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
13 changes: 4 additions & 9 deletions pkg/actors/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,9 @@ func (a *actorsRuntime) callLocalActor(ctx context.Context, req *internalv1pb.In
return nil, fmt.Errorf("failed to read response data: %w", err)

Check warning on line 646 in pkg/actors/actors.go

View check run for this annotation

Codecov / codecov/patch

pkg/actors/actors.go#L646

Added line #L646 was not covered by tests
}

// The .NET SDK indicates Actor failure via a header instead of a bad response.
if _, ok := imRes.Headers()["X-Daprerrorresponseheader"]; ok {
return res, actorerrors.NewActorError(imRes)
// The .NET SDK indicates Actor failure via a header instead of a bad response
if _, ok := res.GetHeaders()["X-Daprerrorresponseheader"]; ok {
return res, actorerrors.NewActorError(res)

Check warning on line 651 in pkg/actors/actors.go

View check run for this annotation

Codecov / codecov/patch

pkg/actors/actors.go#L651

Added line #L651 was not covered by tests
}

return res, nil
Expand Down Expand Up @@ -755,12 +755,7 @@ func (a *actorsRuntime) callRemoteActor(
return nil, teardown, err
}
if len(res.GetHeaders()["X-Daprerrorresponseheader"].GetValues()) > 0 {
invokeResponse, invokeErr := invokev1.InternalInvokeResponse(res)
if invokeErr != nil {
return nil, teardown, invokeErr
}
defer invokeResponse.Close()
return res, teardown, actorerrors.NewActorError(invokeResponse)
return res, teardown, actorerrors.NewActorError(res)

Check warning on line 758 in pkg/actors/actors.go

View check run for this annotation

Codecov / codecov/patch

pkg/actors/actors.go#L757-L758

Added lines #L757 - L758 were not covered by tests
}

return res, teardown, nil

Check warning on line 761 in pkg/actors/actors.go

View check run for this annotation

Codecov / codecov/patch

pkg/actors/actors.go#L761

Added line #L761 was not covered by tests
Expand Down
23 changes: 10 additions & 13 deletions pkg/actors/errors/actor_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,33 @@ import (
"google.golang.org/grpc/codes"

invokev1 "github.com/dapr/dapr/pkg/messaging/v1"
internalv1pb "github.com/dapr/dapr/pkg/proto/internals/v1"
)

// ActorError is an error returned by an Actor via a header + body in the method's response.
type ActorError struct {
body []byte
headers invokev1.DaprInternalMetadata
headers map[string]*internalv1pb.ListStringValue
contentType string
statusCode int
message string
}

func NewActorError(invokeResponse *invokev1.InvokeMethodResponse) error {
if invokeResponse == nil {
func NewActorError(res *internalv1pb.InternalInvokeResponse) error {
if res == nil {
return fmt.Errorf("could not parse actor error: no response object")
}

body, err := invokeResponse.RawDataFull()
if err != nil {
return fmt.Errorf("could not read actor error: %s", err)
}

statusCode := int(invokeResponse.Status().GetCode())
if !invokeResponse.IsHTTPResponse() {
statusCode := int(res.GetStatus().GetCode())
if !res.IsHTTPResponse() {
statusCode = invokev1.HTTPStatusFromCode(codes.Code(statusCode))
}

msg := res.GetMessage()
return &ActorError{
body: body,
headers: invokeResponse.Headers(),
contentType: invokeResponse.ContentType(),
body: msg.GetData().GetValue(),
headers: res.GetHeaders(),
contentType: msg.GetContentType(),
statusCode: statusCode,
message: "actor error with details in body",
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/grpc/api_daprinternal.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@ func (a *api) CallActor(ctx context.Context, in *internalv1pb.InternalInvokeRequ
// We don't do resiliency here as it is handled in the API layer. See InvokeActor().
res, err := a.Actors.Call(ctx, in)

Check warning on line 285 in pkg/grpc/api_daprinternal.go

View check run for this annotation

Codecov / codecov/patch

pkg/grpc/api_daprinternal.go#L285

Added line #L285 was not covered by tests
if err != nil {
// We have to remove the error to keep the body, so callers must re-inspect for the header in the actual response.
actorErr, isActorErr := actorerrors.As(err)
if res != nil && isActorErr {

Check warning on line 288 in pkg/grpc/api_daprinternal.go

View check run for this annotation

Codecov / codecov/patch

pkg/grpc/api_daprinternal.go#L288

Added line #L288 was not covered by tests
// We have to remove the error to keep the body, so callers must re-inspect for the header in the actual response.
res.Message.Data = &anypb.Any{
Value: actorErr.Body(),

Check warning on line 291 in pkg/grpc/api_daprinternal.go

View check run for this annotation

Codecov / codecov/patch

pkg/grpc/api_daprinternal.go#L290-L291

Added lines #L290 - L291 were not covered by tests
}
res.Headers = actorErr.Headers()
return res, nil

Check warning on line 294 in pkg/grpc/api_daprinternal.go

View check run for this annotation

Codecov / codecov/patch

pkg/grpc/api_daprinternal.go#L293-L294

Added lines #L293 - L294 were not covered by tests
}

err = status.Errorf(codes.Internal, messages.ErrActorInvoke, err)
Expand Down

0 comments on commit f8d0517

Please sign in to comment.