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

Check whether github.com/pkg/errors can be replaced with standard library functions #12632

Closed
5 of 6 tasks
alexzurbonsen opened this issue May 4, 2022 · 1 comment · Fixed by #12725
Closed
5 of 6 tasks
Assignees

Comments

@alexzurbonsen
Copy link
Contributor

alexzurbonsen commented May 4, 2022

The module github.com/pkg/errors is no longer maintained, see for example pkg/errors#245.

It seems like it can be removed and replaced by standard lib functionality (mainly errors.Errorf --> fmt.Errorf), which includes all of the functionality, except for the stack traces, that are included in the error type from pkg/errors. See for example this comment microsoft/go-winio#227 (comment).

We should probably check whether removal is sensible and if yes replace it.

Progress:

this needs to be fixed in

@alexzurbonsen alexzurbonsen changed the title Replace github.com/pkg/errors with standard library Check whether github.com/pkg/errors can be replaced with standard library functions May 4, 2022
@MoritzThomasHuebner
Copy link
Contributor

MoritzThomasHuebner commented May 16, 2022

Summary

These PRs remove the uses of github.com/pkg/errors which is no longer maintained. However, this change will remove stack traces in the output.

  • Replaces calls of the form errors.Wrap(err, wrap) with fmt.Errorf(wrap + ": %w", err) (or similar).
  • Replaces calls of the form errors.Wrapf(err, wrap, ...vars) with fmt.Errorf(wrap + ": %w", ...vars, err).
  • Replace use of errors.New(fmt.Sprintf(...)) with fmt.Errorf.
  • Replaces calls to github.com/pkg/errors errors.New with errors.New in the standard library.
  • Replaces calls to errors.WithStack(err) with err.
  • Replaces calls to github.com/pkg/errors errors.Cause with errors.Unwrap in the standard library.
  • Replaces a few other calls to github.com/pkg/errors which rarely appear in the project.

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

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 a pull request may close this issue.

2 participants