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(cwg): replace deprecated errors module #12725
refactor(cwg): replace deprecated errors module #12725
Conversation
Thanks for opening a PR! 💯
Howto
More infoPlease take a moment to read through the Magma project's
If this is your first Magma PR, also consider reading
|
f1e9818
to
3bab076
Compare
5fc09d4
to
9d9e837
Compare
@@ -45,7 +44,7 @@ func (m *GatewayCwfConfigs) ValidateModel(context.Context) error { | |||
for _, peer := range m.AllowedGrePeers { | |||
for _, key := range set[peer.IP] { | |||
if swag.Uint32Value(peer.Key) == key { | |||
return errors.New(fmt.Sprintf("Found duplicate peer %s with key %d", peer.IP, key)) | |||
return fmt.Errorf("Found duplicate peer %s with key %d", peer.IP, key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed that the PR description says this would be substituted with errors.New from std lib. I think this way might be nicer (you don't need the Sprintf). But may be adapt the PR summary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Also, I stumbled across a few cases like this in #12724, where there was a Sprintf
inside an errors.New
. When we just change to errors.New
from the std lib, the linter will complain and suggest using fmt.Errorf
instead, as it is done here.
But yes, we should add this case to the summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the summary.
errs := multierror.Append(err, fmt.Errorf("Error while rolling back transaction: %w", rollbackErr)) | ||
err = ConvertStorageErrorToGrpcStatus(errs.ErrorOrNil()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to use multierror in one case but not in the other? And for using multierror at all?
And why do we start passing commitErr and rollbackErr?
There is a similar case in cwf/gateway/services/uesim/servicers/uesim.go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If err
is nil, but the commit fails, there is only one error to be passed on. If err
is not nil, then it tries to roll back, but if that also fails, we have two errors to pass: err
and rollbackErr
, that's why we use a multierror here.
We need to pass commitErr
, because err
is nil by default here due to the if
clause, otherwise we would find an error, but the error we pass is nil, so in the end the error gets ignored.
In the other case we use the multierror to pass on both, err
and rollbackErr
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @wolfseb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so this goes beyond replacing pkg/errors and fixes broken error handling. Probably should mention that in the summary as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to the summary.
8cecfd4
to
85592dc
Compare
1ff0966
to
d0e2cb2
Compare
d0e2cb2
to
f85393d
Compare
f85393d
to
2b8a0ad
Compare
2b8a0ad
to
fbc559a
Compare
@uri200 Want to bring this PR to your attention. Would be great to get a review. Thanks! |
Signed-off-by: Moritz Huebner <moritz.huebner@tngtech.com>
Also fixes an incorrect use of commit/rollback error handling in ue_store_utils.go and uesim.go. Signed-off-by: Moritz Huebner <moritz.huebner@tngtech.com>
fbc559a
to
b10f7a9
Compare
* refactor(cwf): Replaces errors.Wrap[f] with fmt.Errorf. Signed-off-by: Moritz Huebner <moritz.huebner@tngtech.com> * refactor(cwf): Replaces more pkg/errors usages with std lib. Also fixes an incorrect use of commit/rollback error handling in ue_store_utils.go and uesim.go. Signed-off-by: Moritz Huebner <moritz.huebner@tngtech.com>
Fixes #12632 for description
Summary
Remove dependency on "github.com/pkg/errors"
errors.Wrap[f]
withfmt.Errorf
errors.New
with standard liberrors.New
errors.New(fmt.Sprintf(...))
withfmt.Errorf
addToStore
inue_store_utils.go
and ingetUE
inuesim.go
was incorrect.commitErr
androllbackErr
were not logged.err != nil
), we now use amultierror
to propagate botherr
androllbackErr
. The logic here is that the rollback should only be triggered if an error happened before, so both errors should be logged.Test Plan
Run unit tests
Additional Information
Worked in pairing with @wolfseb