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

Refactoring error messages to use %w formatting directive and fix logging issue #314

Merged
merged 9 commits into from
Dec 6, 2023

Conversation

ChaosInTheCRD
Copy link
Collaborator

@ChaosInTheCRD ChaosInTheCRD commented Nov 29, 2023

When looking at #293, it was clear that there were some issues occurring with formatting of error messages:

ERROR failed to create fulcio signer: %!w(*errors.errorString=&{square/go-jose: missing payload in JWS message})

After exploring this, it seemed that using fmt.Errorf to format the error first was the safer way to go, and using the %w formatting directive was worthwhile as it gives returned errors an Unwrap method for unwrapping the argument presented with %w initially (see here).

The result of the refactoring gives the following error message:
ERROR failed to create fulcio signer: square/go-jose: compact JWS format must have three parts

This PR coincides with PR in-toto/go-witness#83 created in the https://github.com/in-toto/go-witness repository.

Note: This is a proposed change to the structure. If anyone wishes to suggest a better way of structuring this I am all ears!

@ChaosInTheCRD ChaosInTheCRD changed the title Refactoring error messages to use %w formatting directive and fix logging issue Refactoring error messages to use %w formatting directive and fix logging issue Nov 29, 2023
cmd/config.go Outdated
Comment on lines 67 to 68
err := fmt.Errorf("failed to set config value: %w", err)
log.Error(err)
Copy link
Member

Choose a reason for hiding this comment

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

Same question as the other PR, any reason to not have this as a single line with log.Errorf()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey 👋 - I answered in the other PR: in-toto/go-witness#83 (comment)

Choose a reason for hiding this comment

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

I went and checked out the other PR but didn't see an explanation for this line break?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry if this was all very unclear. The reason for the splitting out the error formatting to fmt.Errorf is because log.Errorf does not support the %w directive. The reason for not having it all on a single line (e.g., log.Errorf(fmt.Errorf(... was for ease of readability.

After being round the houses with all of this a little bit, I believe we can switch all this to a log.WithError(err).Error(.... I will push said changes to this PR 😄

Copy link

@kriscoleman kriscoleman left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!!

@ChaosInTheCRD
Copy link
Collaborator Author

ChaosInTheCRD commented Dec 5, 2023

logs are not printing correctly after these changes, but this is just because the fix is made in in-toto/go-witness#85 and therefore won't be utilised in in-toto/witness until a new release of in-toto/go-witness is cut.

This has been tested against go-witness with the logging interface changes made and things are working as expected.

ERROR failed to create fulcio signer: square/go-jose: compact JWS format must have three parts

Copy link
Member

@jkjell jkjell left a comment

Choose a reason for hiding this comment

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

Looks good!

@ChaosInTheCRD ChaosInTheCRD merged commit a56715e into in-toto:main Dec 6, 2023
10 checks passed
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.

4 participants