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: Replaces deprecated errors module with fmt #12682

Conversation

MoritzThomasHuebner
Copy link
Contributor

@MoritzThomasHuebner MoritzThomasHuebner commented May 11, 2022

refactoring: Replaced calls to errors.Wrap and errors.Wrapf with fmt.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:

  1. Replaces calls of the form errors.Wrap(err, wrap) with fmt.Errorf(wrap + ": %w", err) (or similar)
  2. Replaces calls of the form errors.Wrapf(err, wrap, ...vars) with fmt.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:

    eap_aka_test.go:48: 
        	Error Trace:	eap_aka_test.go:48
        	Error:      	Received unexpected error:
        	            	I caused this error deliberately.
        	            	Error validating EAP packet
        	            	magma/cwf/gateway/services/uesim/servicers.(*UESimServer).HandleEap
        	            		/home/bmoritz/Documents/magma/cwf/gateway/services/uesim/servicers/eap.go:36
        	            	magma/cwf/gateway/services/uesim/servicers_test.TestEapAkaIdentityRequest
        	            		/home/bmoritz/Documents/magma/cwf/gateway/services/uesim/servicers/eap_aka_test.go:47
        	            	testing.tRunner
        	            		/usr/local/go/src/testing/testing.go:1439
        	            	runtime.goexit
        	            		/usr/local/go/src/runtime/asm_amd64.s:1571

New output

    eap_aka_test.go:48: 
        	Error Trace:	eap_aka_test.go:48
        	Error:      	Received unexpected error:
        	            	Error validating EAP packet: I caused this error deliberately.
        	Test:       	TestEapAkaIdentityRequest

Test Plan

Run unit tests.

Additional Information

This is my first PR!

  • This change is backwards-breaking

@pull-request-size pull-request-size bot added the size/XXL Denotes a Pull Request that changes 1000+ lines. label May 11, 2022
@github-actions
Copy link
Contributor

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions github-actions bot added component: cwf component: feg FEG-gateway related issues component: orc8r Orchestrator-related issue labels May 11, 2022
@MoritzThomasHuebner MoritzThomasHuebner changed the title refactoring: Replaced calls to errors.Wrap and errors.Wrapf with… refactor: Replaced calls to errors.Wrap and errors.Wrapf with… May 11, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 11, 2022

feg-workflow

    2 files  202 suites   37s ⏱️
371 tests 371 ✔️ 0 💤 0
385 runs  385 ✔️ 0 💤 0

Results for commit 26c092f.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented May 11, 2022

agw-workflow

     78 files     123 suites   6m 58s ⏱️
1 162 tests 1 152 ✔️ 9 💤 1
1 194 runs  1 184 ✔️ 9 💤 1

For more details on these failures, see this check.

Results for commit 26c092f.

♻️ This comment has been updated with latest results.

@MoritzThomasHuebner MoritzThomasHuebner force-pushed the Switch_from_github.com/pkg/errors_to_stdlib_errors branch from 9b15bdb to 84c5390 Compare May 11, 2022 07:38
@github-actions
Copy link
Contributor

github-actions bot commented May 11, 2022

cloud-workflow

    1 files    98 suites   1m 8s ⏱️
343 tests 322 ✔️ 0 💤 21

For more details on these failures, see this check.

Results for commit 26c092f.

♻️ This comment has been updated with latest results.

@MoritzThomasHuebner MoritzThomasHuebner force-pushed the Switch_from_github.com/pkg/errors_to_stdlib_errors branch 3 times, most recently from b093abc to f632b0c Compare May 12, 2022 06:39
@MoritzThomasHuebner MoritzThomasHuebner changed the title refactor: Replaced calls to errors.Wrap and errors.Wrapf with… refactor: Replaced calls to errors.Wrap and errors.Wrapf May 12, 2022
@MoritzThomasHuebner MoritzThomasHuebner force-pushed the Switch_from_github.com/pkg/errors_to_stdlib_errors branch from f632b0c to 8ea1e69 Compare May 12, 2022 06:44
@magma magma deleted a comment from github-actions bot May 12, 2022
@magma magma deleted a comment from github-actions bot May 12, 2022
@magma magma deleted a comment from github-actions bot May 12, 2022
err,
"cleanupUnixSocket(logger=_, target.Endpoint=%s)",
path))
panic(fmt.Errorf("cleanupUnixSocket(logger=_, target.Endpoint=%s): %w", path, err))
Copy link
Contributor

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.)

Copy link
Contributor Author

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.

Comment on lines 482 to 507
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
}
Copy link
Contributor

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.)

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@MoritzThomasHuebner MoritzThomasHuebner force-pushed the Switch_from_github.com/pkg/errors_to_stdlib_errors branch 3 times, most recently from 26c092f to 5e421be Compare May 16, 2022 00:19
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>
@MoritzThomasHuebner MoritzThomasHuebner force-pushed the Switch_from_github.com/pkg/errors_to_stdlib_errors branch from 5e421be to ec7f48b Compare May 16, 2022 00:47
@MoritzThomasHuebner MoritzThomasHuebner changed the title refactor: Replaced calls to errors.Wrap and errors.Wrapf refactor: Replaces deprecated errors module with fmt May 16, 2022
@MoritzThomasHuebner MoritzThomasHuebner deleted the Switch_from_github.com/pkg/errors_to_stdlib_errors branch May 18, 2022 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: cwf component: feg FEG-gateway related issues component: orc8r Orchestrator-related issue size/XXL Denotes a Pull Request that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants