DEV Community

Discussion on: Go, I love you, but you're bringing me down.

Collapse
opennota profile image
opennota

I've filed an issue about the unclear panic message with nil interfaces:
github.com/golang/go/issues/21152
Do you have anything to say?

Collapse
loderunner profile image
Charles Francoise Author

Great! Nothing to add, you pretty much nailed it. Your example is clear and concise. Thumbs upped the issue.

My example is more of a "working case" where the lack of compiler checks or better panic messages can lead to long debugging before you get that forehead-slapping revelation.

Collapse
opennota profile image
opennota

@aclements asked:
Would it be an improvement simply for the message to say "nil value" instead of "nil pointer"? Did "nil pointer" lead you in the wrong direction?

Thread Thread
loderunner profile image
Charles Francoise Author

I think the real issue is that the error message doesn't make it clear that it's the embedded interface that is nil. I looked for a nil member, or the instance being nil itself, but I didn't think of checking the embedded interfaces.

I guess it's also part of being used to inheritance from C++ and Java (and generally learning to code in the 90s-00s), and I'll get used to double-checking embedded types. But it wouldn't hurt to have a more explicit error message, that would shave a few minutes off debugging the panic, even for experienced Go practitioners. And it would also ease the path for newcomers.