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

feat: refactor error message format #1675

Merged
merged 5 commits into from
Aug 9, 2024

Conversation

binbin-li
Copy link
Collaborator

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

Description

What this PR does / why we need it:

This PR will refactor the message format returned by Error(). The new format is following the proposed improvement from #1662

Note: this pr is based on #1671, please check the actual diff at: binbin-li#209

In general, for a nested Ratify error, we'll return a message in format:
<Error Code>: <Error Description>: <Error Reason>: <Remediation>,
where Error Code is the error code of the root error,
Error Description is concatenated details of all nested errors,
Error Reason is the detail or original error of the root error,
and Remediation is the remediation of the root error.

Let's take the below nested error as example:

{
  Code: "TOP_ERR_CODE",
  Detail: "top error detail",
  Remediation: "top error remediation",
  OriginalError: {
    Code: "ROOT_ERR_CODE",
    Detail: "root error detail",
    Remediation: "root error remediation",
    OriginalError: "http request failed with 401"
  }
}

Then the Error() method should return a string: ROOT_ERR_CODE: top error detail: root error detail: http request failed with 401: root error remediation.
GetDetail() should return string: top error detail: root error detail.
GetErrorReason() should return string: http request failed with 401.
GetRemeidation() should return string: root error remediation.

Therefore, we would stop printing all fields from the Error. In this PR, we keep all existing fields under Error struct. And if the new error format looks good in the following releases, we'll start remove those unused fields gradually.

Examples:
Error log before change:
time=2024-07-31T14:04:45.027923414Z level=error msg=Original Error: (Original Error: (Original Error: (json: cannot unmarshal number into Go struct field azureWIAuthProviderConf.clientID of type string), Error: config invalid, Code: CONFIG_INVALID, Component Type: authProvider, Detail: failed to parse auth provider configuration), Error: auth denied, Code: AUTH_DENIED, Component Type: authProvider), Error: plugin init failure, Code: PLUGIN_INIT_FAILURE, Component Type: referrerStore, Detail: failed to create auth provider from configuration

time=2024-07-31T14:02:52.767626288Z level=error msg=Original Error: (failed to find plugin "notation22" in paths [/.ratify/plugins]), Error: plugin not found, Code: PLUGIN_NOT_FOUND, Component Type: verifier, Detail: plugin not found

Error log after change:
time=2024-07-31T13:48:09.976909601Z level=error msg=CONFIG_INVALID: failed to create auth provider from configuration: failed to parse auth provider configuration: json: cannot unmarshal number into Go struct field azureWIAuthProviderConf.clientID of type string

time=2024-07-31T13:57:55.837222446Z level=error msg=PLUGIN_NOT_FOUND: plugin not found: failed to find plugin "notation22" in paths [/.ratify/plugins]

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: #1655

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

  • Test A
  • Test B

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 marked this pull request as draft July 31, 2024 08:29
@binbin-li binbin-li changed the title Error log message [DO NOT REVIEW] Error log message Jul 31, 2024
@binbin-li binbin-li force-pushed the error-log-message branch 3 times, most recently from 52d1954 to a2aa5f6 Compare July 31, 2024 14:12
@binbin-li binbin-li changed the title [DO NOT REVIEW] Error log message Error log message Jul 31, 2024
Copy link

codecov bot commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 96.55172% with 2 lines in your changes missing coverage. Please review.

Files Patch % Lines
errors/types.go 96.55% 1 Missing and 1 partial ⚠️
Files Coverage Δ
errors/types.go 90.47% <96.55%> (+1.58%) ⬆️

@binbin-li binbin-li changed the title Error log message feat: refactor error message format Aug 1, 2024
@binbin-li binbin-li marked this pull request as ready for review August 1, 2024 04:44
@binbin-li binbin-li force-pushed the error-log-message branch 3 times, most recently from 6d61b27 to 34081c4 Compare August 1, 2024 07:09
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 good to me. thanks Binbin

@binbin-li binbin-li merged commit e8f8000 into ratify-project:dev Aug 9, 2024
18 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.

Refactor the nested error structure
2 participants