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

Dedup go errors #1496

Merged
merged 9 commits into from
Nov 16, 2023
Merged

Dedup go errors #1496

merged 9 commits into from
Nov 16, 2023

Conversation

VenelinMartinov
Copy link
Contributor

@VenelinMartinov VenelinMartinov commented Oct 30, 2023

The muxer previously de-duplicated CheckFailures but not go errors. This PR should add that and address #1418 but not the original issue in pulumi/pulumi-aws#2285 (comment). See #1418 (comment)

This fixes duplicated error messages in the aws-provider when no aws region is specified.

Before:

    error: rpc error: code = Unknown desc = 2 errors occurred:
    	* unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

    	* unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

After:

    error: rpc error: code = Unknown desc = unable to validate AWS credentials.
    Details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, failed to resolve service endpoint, endpoint rule error, Invalid Configuration: Missing Region
    Make sure you have set your AWS region, e.g. `pulumi config set aws:region us-west-2`.

@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0ac62de) 62.02% compared to head (ff6ec62) 57.96%.
Report is 6 commits behind head on master.

Files Patch % Lines
x/muxer/muxer.go 0.00% 6 Missing ⚠️
testing/x/replay.go 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1496      +/-   ##
==========================================
- Coverage   62.02%   57.96%   -4.06%     
==========================================
  Files         185      286     +101     
  Lines       32895    39695    +6800     
==========================================
+ Hits        20402    23009    +2607     
- Misses      11353    15344    +3991     
- Partials     1140     1342     +202     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks good. There is code on L154 that does almost the same thing. I would probably change the comment on L154 to say "failures" instead of "errors" to help disambiguate.

Can you add a test for this?

@@ -181,8 +181,15 @@ func replay[Req protoreflect.ProtoMessage, Resp protoreflect.ProtoMessage](
assert.NoError(t, err)

resp, err := serve(ctx, req)
if err != nil && entry.Errors != nil {
errList := make([]string, 0)
unmarshalErr := json.Unmarshal(entry.Errors, &errList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry.Errors is a JSON list that is user provided, but we still assert that it should have a length of 1. What happens if we want to test that we have multiple errors?

Copy link
Contributor Author

@VenelinMartinov VenelinMartinov Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the provider can return multiple errors as far as I can see. It seems to combine all the errors into one. The CheckConfig method can only return one error value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't have multiple errors, when why do we unmarshal entry.Errors into a list. I think we can simplify this whole block into

if err != nil && entry.Error != nil {
	assert.Equal(t, entry.Error, err.Error())
	return
}

This would involve changing the field Errors json.RawMessage to Error *string. We would then represent the error from fmt.Errorf("my-error") as &"my-error". No error would be represented as nil.

x/muxer/tests/muxer_test.go Outdated Show resolved Hide resolved
x/muxer/tests/muxer_test.go Show resolved Hide resolved
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand the complexity for one of the tests, but otherwise this looks great! LGTM

@@ -181,8 +181,15 @@ func replay[Req protoreflect.ProtoMessage, Resp protoreflect.ProtoMessage](
assert.NoError(t, err)

resp, err := serve(ctx, req)
if err != nil && entry.Errors != nil {
errList := make([]string, 0)
unmarshalErr := json.Unmarshal(entry.Errors, &errList)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't have multiple errors, when why do we unmarshal entry.Errors into a list. I think we can simplify this whole block into

if err != nil && entry.Error != nil {
	assert.Equal(t, entry.Error, err.Error())
	return
}

This would involve changing the field Errors json.RawMessage to Error *string. We would then represent the error from fmt.Errorf("my-error") as &"my-error". No error would be represented as nil.

x/muxer/tests/muxer_test.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants