in-toto / witness

Witness is a pluggable framework for software supply chain risk management. It automates, normalizes, and verifies software artifact provenance.
https://witness.dev
Apache License 2.0
416 stars 60 forks source link

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

Closed ChaosInTheCRD closed 12 months ago

ChaosInTheCRD commented 1 year ago

When looking at https://github.com/in-toto/witness/issues/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 https://github.com/in-toto/go-witness/pull/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 commented 1 year ago

logs are not printing correctly after these changes, but this is just because the fix is made in https://github.com/in-toto/go-witness/pull/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