Skip to content

ROX-10259: Remove deprecated errorhelpers errors#1372

Merged
mtodor merged 9 commits intomasterfrom
mtodor/ROX-10259-remove-deprecated-errors
Apr 25, 2022
Merged

ROX-10259: Remove deprecated errorhelpers errors#1372
mtodor merged 9 commits intomasterfrom
mtodor/ROX-10259-remove-deprecated-errors

Conversation

@mtodor
Copy link
Copy Markdown
Contributor

@mtodor mtodor commented Apr 21, 2022

Description

We have removed deprecated errorhelpers errors and changed to a new approach provided by errox package.

Note: If a review of the whole PR is difficult because we are touching too many files here then it is possible to review commit by commit.

Checklist

  • Investigated and inspected CI test results
  • [ ] Unit test and regression tests added - nothing is added, some of them are modified to match replacements
  • [ ] Evaluated and added CHANGELOG entry if required - not relevant because underlying changes are done
  • [ ] Determined and documented upgrade steps - nothing relevant for upgrade steps
  • [ ] Documented user facing changes (create PR based on stackrox/openshift-docs and merge into rhacs-docs) - no user-facing changes

Testing Performed

The following things are tested locally:

  • that make image works
  • deploy the stack locally and access it over the Web interface
  • make style works, so that the linting of all go files is correct. With it we are checking that correct packages are included or removed

@ghost
Copy link
Copy Markdown

ghost commented Apr 21, 2022

Tag for build #457678 is 3.69.x-463-ga0129aa273.

💻 For deploying this image using the dev scripts, run the following first:

export MAIN_IMAGE_TAG='3.69.x-463-ga0129aa273'

🕹️ A roxctl binary can be downloaded from the CircleCI artifacts.

}
if !exists {
return nil, errors.Wrapf(errorhelpers.ErrNotFound, "alert with id '%s' does not exist", request.GetId())
return nil, errors.Wrapf(errox.NotFound, "alert with id '%s' does not exist", request.GetId())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be possible to replace such cases with

Suggested change
return nil, errors.Wrapf(errox.NotFound, "alert with id '%s' does not exist", request.GetId())
return nil, errox.NotFound.Newf("alert with id '%s' does not exist", request.GetId())

?
That would remove the useless "not found" from the resulting error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@0x656b694d Thank you for the suggestion. We want to make changes in several PRs so that it's easier to review them. This PR is the simple removal of pkg/errorhelpers/errors.go. Next will be removing helper (wrapper) functions for CausedBy. After that, we can start with further polishing. We can decide if we want to keep the message prefix or remove it.

@mtodor mtodor requested review from a team, parametalol and rukletsov April 22, 2022 06:05
@mtodor mtodor marked this pull request as ready for review April 22, 2022 06:05
@mtodor mtodor requested a review from a team as a code owner April 22, 2022 06:05
Copy link
Copy Markdown
Member

@rukletsov rukletsov left a comment

Choose a reason for hiding this comment

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

Looks like a bulk replace — no brainer. I left a couple of comments, not as immediate suggestions but more as sharing my thoughts about the current state and possible improvements.

return s.getScannerCertExpiry(ctx)
}
return nil, errors.Wrapf(errorhelpers.ErrInvalidArgs, "invalid component: %v", request.GetComponent())
return nil, errors.Wrapf(errox.InvalidArgs, "invalid component: %v", request.GetComponent())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, this another example of a useless prefix: "invalid arguments: invalid component: orange ocean"

if len(result) < len(ids) {
missingIds := set.NewStringSet(ids...).Difference(search.ResultsToIDSet(result))
return errors.Wrapf(errorhelpers.ErrNotFound, "Following CVEs not found: %s", strings.Join(missingIds.AsSlice(), ", "))
return errors.Wrapf(errox.NotFound, "Following CVEs not found: %s", strings.Join(missingIds.AsSlice(), ", "))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And another one, introducing tautology (and capitalized!): "not found: Following CVEs not found: CVE-xxyyz"

}
if err := reconcileNotifierConfigWithExisting(updateRequest.GetNotifier(), existingNotifierConfig); err != nil {
return errors.Wrap(errorhelpers.ErrInvalidArgs, err.Error())
return errors.Wrap(errox.InvalidArgs, err.Error())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And this is a good use case for .CausedBy() I think. The pattern errors.Wrap(sentinel, err.Error()) was mostly introduced in https://github.com/stackrox/rox/pull/8239 where we replaced gRPC status errors with this pattern (because we introduced automatic sentinel -> gRPC error conversion before). However, I'm not sure whether all occurrences of errors.Wrap(sentinel, err.Error()) can be auto replaced, probably we'll need to look at each of them.

It is unfortunate that we only keep the error message here. In the future we might want to also track and print stack traces to the log and having a tailored version .CausedBy(errorWithStackTrace) will help us to preserve the stack of the cause.

@mtodor mtodor mentioned this pull request Apr 22, 2022
1 task
@viswajithiii viswajithiii removed the request for review from a team April 22, 2022 18:29
@mtodor mtodor merged commit 5a5060f into master Apr 25, 2022
@mtodor mtodor deleted the mtodor/ROX-10259-remove-deprecated-errors branch April 25, 2022 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants