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

refactor: refactor error handling #956

Merged
merged 9 commits into from
Aug 17, 2023

Conversation

binbin-li
Copy link
Collaborator

@binbin-li binbin-li commented Jul 31, 2023

Description

What this PR does / why we need it:

  1. Refactor most errors to a custom error struct.
  2. Each error would have an error code for fast searching.
  3. For plugin errors, there would be componentType indicating the plugin type, and pluginName indicating the plugin name, e.g. verifier as componentType, and notation-verifier as pluginName.
  4. Add OriginalError so that we can trace the root error.
  5. Add Stack so that we can debug the stack trace.
  6. Add a doc listing all errors. More work need to be done in the future to have more information on debugging each error.

Design doc: https://hackmd.io/@H7a8_rG4SuaKwzu4NLT-9Q/HJ6bNe2c2

The exported error codes could be checked on pkg.go.dev, just like this: https://pkg.go.dev/github.com/distribution/distribution@v2.8.2+incompatible/registry/api/errcode#pkg-variables

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):

Fixes #856

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Helm Chart Change (any edit/addition/update that is necessary for changes merged to the main branch)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration

I tested the error format in both add-on service and CLI tool.

  1. Add-on service.
    The service log would look like:
    image

  2. CLI.
    image

Checklist:

  • Does the affected code have corresponding tests?
  • Are the changes documented, not just with inline documentation, but also with conceptual documentation such as an overview of a new feature, or task-based documentation like a tutorial? Consider if this change should be announced on your project blog.
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have appropriate license header?

Post Merge Requirements

  • MAINTAINERS: manually trigger the "Publish Package" workflow after merging any PR that indicates Helm Chart Change

@binbin-li binbin-li self-assigned this Jul 31, 2023
@binbin-li binbin-li marked this pull request as draft July 31, 2023 15:27
@akashsinghal
Copy link
Collaborator

Thanks for this quality work @binbin-li! Would it be possible to get a screenshot of what the new formatted logs look like? Same for the error message from GK and the CLI?

@binbin-li binbin-li force-pushed the refactor-error branch 2 times, most recently from 191cbb2 to 24e71bd Compare August 1, 2023 14:06
@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Patch coverage: 55.80% and project coverage change: +0.72% 🎉

Comparison is base (ab7636f) 57.45% compared to head (8fab6bd) 58.17%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #956      +/-   ##
==========================================
+ Coverage   57.45%   58.17%   +0.72%     
==========================================
  Files          90       91       +1     
  Lines        5326     5447     +121     
==========================================
+ Hits         3060     3169     +109     
- Misses       1956     1964       +8     
- Partials      310      314       +4     
Files Changed Coverage Δ
pkg/common/oras/authprovider/authprovider.go 44.11% <0.00%> (ø)
pkg/policyprovider/configpolicy/configpolicy.go 92.59% <0.00%> (ø)
pkg/referrerstore/factory/factory.go 56.92% <0.00%> (ø)
pkg/referrerstore/oras/cache.go 72.72% <0.00%> (ø)
pkg/verifier/factory/factory.go 60.93% <0.00%> (ø)
pkg/verifier/plugin/plugin.go 70.83% <0.00%> (ø)
httpserver/handlers.go 74.34% <7.14%> (ø)
.../common/oras/authprovider/k8secret_authprovider.go 15.68% <7.14%> (ø)
pkg/referrerstore/oras/oras.go 68.83% <20.00%> (ø)
...kg/common/oras/authprovider/authproviderfactory.go 62.85% <25.00%> (ø)
... and 14 more

... and 1 file with indirect coverage changes

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

@binbin-li binbin-li changed the title feat: refactor error handling refactor: refactor error handling Aug 3, 2023
@binbin-li binbin-li marked this pull request as ready for review August 3, 2023 06:55
@susanshi
Copy link
Collaborator

susanshi commented Aug 9, 2023

Thanks for this quality work @binbin-li! Would it be possible to get a screenshot of what the new formatted logs look like? Same for the error message from GK and the CLI?

thanks the sample errors in the images. Just to clarify , when do we add stack trace to errors ? stack trace is needed when something is wrong ( ratify code error) , i want to make sure when Ratify successfully run validation,we don't pass a stack trace on a bad image. Also if it is a configuration error, customer need to fix the configuration, but they won't need to investigate the code base

Copy link
Collaborator

@susanshi susanshi left a comment

Choose a reason for hiding this comment

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

this is a great improvement @binbin-li over our current message, left some comments.

docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
errors/errors.go Outdated Show resolved Hide resolved
errors/pluginerrors.go Outdated Show resolved Hide resolved
errors/pluginerrors.go Outdated Show resolved Hide resolved
errors/pluginerrors.go Outdated Show resolved Hide resolved
errors/pluginerrors.go Outdated Show resolved Hide resolved
httpserver/handlers.go Show resolved Hide resolved
@binbin-li binbin-li force-pushed the refactor-error branch 4 times, most recently from a3cffef to 67c7a62 Compare August 14, 2023 15:59
@binbin-li binbin-li mentioned this pull request Aug 15, 2023
1 task
docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
docs/reference/errors.md Outdated Show resolved Hide resolved
errors/pluginerrors.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@susanshi susanshi left a comment

Choose a reason for hiding this comment

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

Looks great! lets sync on the TSG

pkg/certificateprovider/azurekeyvault/provider.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@susanshi susanshi left a comment

Choose a reason for hiding this comment

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

Looks great! lets sync on the TSG

@binbin-li
Copy link
Collaborator Author

Looks great! lets sync on the TSG

synced offline. thanks a lot for feedback @susanshi

Copy link
Collaborator

@susanshi susanshi left a comment

Choose a reason for hiding this comment

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

LGTM. thanks!

@binbin-li binbin-li merged commit b600277 into ratify-project:main Aug 17, 2023
14 of 15 checks passed
junczhu pushed a commit to ZAFT-Armored-Keeper-of-Unity/ratify that referenced this pull request Aug 23, 2023
junczhu added a commit to ZAFT-Armored-Keeper-of-Unity/ratify that referenced this pull request Aug 23, 2023
fix: fix cert-rotator test (ratify-project#992)

chore: bump github.com/aws/aws-sdk-go-v2/config from 1.18.32 to 1.18.33 (ratify-project#988)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Akash Singhal <akashsinghal@microsoft.com>

feat: add graceful shutdown for http server (ratify-project#949)

fix: Updating akv cert provider to use getSecret (ratify-project#957)

Signed-off-by: Susan Shi <huish@microsoft.com>

chore: bump golangci/golangci-lint-action from 3.6.0 to 3.7.0 (ratify-project#997)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

chore: bump actions/setup-go from 4.0.1 to 4.1.0 (ratify-project#996)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

fix: adding experimental to dynamic plugin flag (ratify-project#980)

refactor: refactor error handling (ratify-project#956)

docs: add notaryv2 upgrade doc (ratify-project#999)

chore: update assign.yaml template

chore: update library templates

chore: update library templates2

chore: update library templates fix typo

chore: update library templates array
bspaans pushed a commit to bspaans/ratify that referenced this pull request Oct 17, 2023
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.

Add custom wrapped errors
3 participants