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
runtime: panic should print named string types as is #37531
Comments
The relevant code is |
Change https://golang.org/cl/221779 mentions this issue: |
Change https://golang.org/cl/221687 mentions this issue: |
@dsnet In the original use case you shared, have you considered using the pattern of panicking with a value of type type MyString string
panic(fmt.Errorf("%v", MyString("hello")))
// Output:
// panic: hello That pattern enables one to make use of all high-level printing capabilities of You can customize it with "%T" verb if you want to see the type name, add a description in front of the value, etc. It can makes the diff smaller if you decide to change the panic into a return statement (since It scales better. Consider that CL 221779 adds some complexity to the type MyStruct struct {
Text string
}
panic(MyStruct{"hello"})
// Output:
// panic: (main.MyStruct) (0x9ba80,0x40c018) type MyStruct struct {
Text string
}
panic(fmt.Errorf("problem with foo: %#v", MyStruct{"hello"}))
// Output:
// panic: problem with foo: main.MyStruct{Text:"hello"} I don't think we should try to add all of complexity of What do you think about this? |
Generally, I use This specific situation occurred because of something like the following:
where However, I missed the fact that concatenating an untyped string constant to a typed string variable results in a string of the named string type. This results in an unhelpful panic message containing only pointers which made debugging the issue from a server log more difficult. |
Consider the following:
This currently prints:
I expect it to print the actual string contents:
Keeping the name of the type is debatable, but printing the address is unhelpful.
The text was updated successfully, but these errors were encountered: