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

Use default error formating when errors.Wrap isn't implemented. #86

Merged
merged 3 commits into from
Oct 9, 2024

Conversation

orsenthil
Copy link
Member

…plemented.

Use default error formatting when the error wrap isn't available.

The error message that was seen was

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…plemented.

Use default error formatting when the error wrap isn't available.

The error message that was seen was

```{"level":"error","ts":"2024-06-30T10:52:42.597Z","caller":"ebpf/bpf_client.go:563","msg":"failed to find device by name eni3d4ff16416b: %!w(netlink.LinkNotFoundError={0xc0007ae7c0})"}
```
@orsenthil orsenthil requested a review from a team as a code owner July 15, 2024 13:30
@orsenthil orsenthil changed the title Use default error formating instead of wrap when errors.Wrap isn't im… Use default error formating when errors.Wrap isn't implemented. Jul 15, 2024
@achevuru
Copy link
Contributor

Were you able to test these changes?

@orsenthil
Copy link
Member Author

@achevuru - this is test.

package main

import (
	"errors"
	"fmt"

	"github.com/aws/aws-ebpf-sdk-go/pkg/logger"
)

func main() {
	var log = logger.Get()

	e := errors.New("new error")
	wrapsErr := fmt.Errorf("wrapped error %w ", e)

	log.Errorf("test-error with w %w", e)
	log.Errorf("test-error with w %w", wrapsErr)

	log.Errorf("test-error with v %v", e)
	log.Errorf("test-error with v %v", wrapsErr)

}

output

$ cat /var/log/aws-routed-eni/ebpf-sdk.log
...

{"level":"info","ts":"2024-08-26T22:54:44.986Z","caller":"test2/main.go:11","msg":"Initialized new logger as an existing instance was not found"}
{"level":"error","ts":"2024-08-26T22:54:44.986Z","caller":"runtime/proc.go:272","msg":"test-error with w %!w(*errors.errorString=&{new error})"}
{"level":"error","ts":"2024-08-26T22:54:44.986Z","caller":"runtime/proc.go:272","msg":"test-error with w %!w(*fmt.wrapError=&{wrapped error new error  0xc000014260})"}
{"level":"error","ts":"2024-08-26T22:54:44.986Z","caller":"runtime/proc.go:272","msg":"test-error with v new error"}
{"level":"error","ts":"2024-08-26T22:54:44.986Z","caller":"runtime/proc.go:272","msg":"test-error with v wrapped error new error "}

Copy link
Contributor

@yash97 yash97 left a comment

Choose a reason for hiding this comment

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

lgtm 🚀

@orsenthil orsenthil merged commit 0581d0e into main Oct 9, 2024
2 checks passed
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 this pull request may close these issues.

3 participants