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

fix safeError & safeString for json format #20

Merged
merged 2 commits into from Mar 20, 2022
Merged

fix safeError & safeString for json format #20

merged 2 commits into from Mar 20, 2022

Conversation

dwiyanr
Copy link
Contributor

@dwiyanr dwiyanr commented Mar 4, 2022

relates to #19

Copy link
Member

@ChrisHines ChrisHines left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, and thanks for including tests!

The implementation and tests look good here, I think we can improve the specific messages we log for the panics so I've provided alternatives that I think make it more clear what has gone wrong in these situations. With those changes this will be ready to merge.

json_logger.go Outdated
@@ -68,7 +68,7 @@ func safeString(str fmt.Stringer) (s string) {
if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() {
s = "NULL"
} else {
panic(panicVal)
s = fmt.Sprintf("panic stringer value: %v", panicVal)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make it more obvious something went wrong with getting the string (or error). I think this message may not be prominent enough.

Let's change this to:

fmt.Sprintf("PANIC in String method: %v", panicVal)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure! updated.

json_logger.go Outdated
@@ -82,7 +82,7 @@ func safeError(err error) (s interface{}) {
if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() {
s = nil
} else {
panic(panicVal)
s = fmt.Sprintf("panic error value: %v", panicVal)
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above let's make this:

fmt.Sprintf("PANIC in Error method: %v", panicVal)

@dwiyanr dwiyanr requested a review from ChrisHines March 15, 2022 12:49
@ChrisHines
Copy link
Member

Thanks for the contribution!

@ChrisHines ChrisHines merged commit 2b8dc2b into go-kit:main Mar 20, 2022
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.

None yet

2 participants