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

node/bindnode: plug the footgun that is using the repr-level enum strings in Go #348

Closed
mvdan opened this issue Feb 3, 2022 · 1 comment · Fixed by #430
Closed

node/bindnode: plug the footgun that is using the repr-level enum strings in Go #348

mvdan opened this issue Feb 3, 2022 · 1 comment · Fixed by #430
Assignees

Comments

@mvdan
Copy link
Contributor

mvdan commented Feb 3, 2022

A user ran into a bug in the form of:

type GraphSyncLinkAction enum {
   | Present             ("p")
   | Missing             ("m")
} representation string

then backed in Go by a string, like:

type LinkAction string
const (
	LinkActionPresent = LinkAction("p")
	LinkActionMissing = LinkAction("m")
)

This didn't work:

AsString: "p" is not a valid member of enum GraphSyncLinkAction

The fix was to use the strings for the enum members at the type level, rather than the representation level, which is how bindnode works:

type LinkAction string
const (
	LinkActionPresent = LinkAction("Present")
	LinkActionMissing = LinkAction("Missing")
)

This is all working as intended, but the mistake is easy to make, and the error didn't really point the user in the right direction.

We should probably do something here like a better error message, such as:

AsString: "p" is not a valid member of enum GraphSyncLinkAction (bindnode works at the type level; did you mean "Present"?)

@rvagg
Copy link
Member

rvagg commented May 24, 2022

Genuine footgun, also hit in this commit (hence failing tests): dfa7373

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎉 Done
Development

Successfully merging a pull request may close this issue.

2 participants