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: Replaces deprecated errors module with fmt #12682
refactor: Replaces deprecated errors module with fmt #12682
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
|
errors.Wrap
and errors.Wrapf
with…errors.Wrap
and errors.Wrapf
with…
9b15bdb
to
84c5390
Compare
b093abc
to
f632b0c
Compare
errors.Wrap
and errors.Wrapf
with…f632b0c
to
8ea1e69
Compare
src/go/agwd/server/server.go
Outdated
err, | ||
"cleanupUnixSocket(logger=_, target.Endpoint=%s)", | ||
path)) | ||
panic(fmt.Errorf("cleanupUnixSocket(logger=_, target.Endpoint=%s): %w", path, err)) |
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.
While in general cleanup is nice, we might not want to change this in the same commit and PR, as the PR is already big enough. (Also lines below.)
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.
This line and other instances of this in the file also change errors.Wrapf
to fmt.Errorf
. The reformatting was incidental.
func (tr *TestRunner) WaitForEnforcementStatsForRuleGreaterThanOrDoesNotExistFunc(imsi, ruleID string, min uint64) (*lteprotos.RuleRecord, bool) { | ||
fmt.Printf("\tWaiting until %s, %s has more than %d bytes in enforcement stats or rule does not exist ...\n", imsi, ruleID, min) | ||
records, err := tr.GetPolicyUsage() | ||
if err != nil { | ||
return nil, false | ||
} | ||
imsi = prependIMSIPrefix(imsi) | ||
if records[imsi] == nil { | ||
// Session is gone | ||
fmt.Printf("\tSession for %s, does not exist...\n", imsi) | ||
return nil, true | ||
} | ||
record := records[imsi][ruleID] | ||
if record == nil { | ||
// Session is gone | ||
fmt.Printf("\tRule %s for %s, does not exist...\n", ruleID, imsi) | ||
return nil, true | ||
} | ||
txBytes := record.BytesTx | ||
if record.BytesTx < min { | ||
return record, false | ||
} | ||
fmt.Printf("\t\u2713 %s, %s now passed %d > %d in enforcement stats!(%d%%)\n", | ||
imsi, ruleID, txBytes, min, 100*txBytes/min) | ||
return record, true | ||
} |
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.
This seems to be a white-space change only. While in general cleanup is nice, we might not want to change this in the same commit and PR, as the PR is already big enough. (Also lines below.)
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 removed this white space change.
newVolumeStr := fmt.Sprintf("%dK", newVolume/1000) | ||
|
||
req.Volume = &wrappers.StringValue{Value: newVolumeStr} | ||
fmt.Printf("- not enough traffic genereted, sending %dKB more. Will be around %d%% of volume requested\n", | ||
newVolume/1000, | ||
100 * (record.BytesTx+newVolume)/totalVolume, | ||
100*(record.BytesTx+newVolume)/totalVolume, |
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.
Those changes of white-spaces around operators seem rather inconsistent and every PR seems to want to change them. I think in this PR, we should not touch them.
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 removed this white space change.
26c092f
to
5e421be
Compare
Also added back in a nil check in `collectGarbageSQL` in `orc8r/clound/go/syncstore/store_writer.go` Signed-off-by: Moritz Huebner <moritz.huebner@tngtech.com>
5e421be
to
ec7f48b
Compare
refactoring: Replaced calls to
errors.Wrap
anderrors.Wrapf
withfmt.Errorf
Summary
This PR starts the process of removing the uses of github.com/pkg/errors which is no longer maintained. However, this change will remove stack traces in the output.
The issue was raised in #12632. The remaining uses of "github.com/pkg/errors" are removed in #12683. Splitting these PRs should make them easier to review.
This PR:
errors.Wrap(err, wrap)
withfmt.Errorf(wrap + ": %w", err)
(or similar)errors.Wrapf(err, wrap, ...vars)
withfmt.Errorf(wrap + ": %w", ...vars, err)
Go also automatically formatted some files while I was making these changes. There are a few white spaces that were added or removed unrelated to the change in error wrapping due to automatic formatting.
I attached an example below of the change in output. I obtained this by modifying the source code so a test would fail.
Old output:
New output
Test Plan
Run unit tests.
Additional Information
This is my first PR!