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

"invalid key" errors don't print themselves properly #167

Open
mvdan opened this issue Apr 27, 2021 · 5 comments
Open

"invalid key" errors don't print themselves properly #167

mvdan opened this issue Apr 27, 2021 · 5 comments
Labels
good first issue Good issue for new contributors

Comments

@mvdan
Copy link
Contributor

mvdan commented Apr 27, 2021

invalid key for map GulpoStruct: %!q(*basicnode.plainString=0xc000097da0): no such field

The Error method attempts to use %q for an ipld.Node, which will generally not work. It should probably use something like AsString instead, unless we have a better way to print nodes for human reading.

https://github.com/ipld/go-ipld-prime/blob/v0.9.0/errors.go#L95-L101

We should probably look through ipld-prime and fix all uses of %s, %q, %v and so on with ipld.Node, because I think none of those are guaranteed to work.

@mvdan mvdan added the good first issue Good issue for new contributors label Nov 12, 2021
@warpfork
Copy link
Collaborator

warpfork commented Nov 16, 2021

We could consider use of printer.Sprint for this now, which was introduced since this issue was first raised.

It might be overkill for this case (?), but might be the right thing to default to if looking at lots of cases of stringing.

@smagdali
Copy link

smagdali commented Feb 4, 2022

(PL-Launchpad newbie) Oh, this sounds like my kind of thing.

@mvdan
Copy link
Contributor Author

mvdan commented Feb 4, 2022

Go for it! Note that the type now lives under the schema package.

Also note that we shouldn't close this issue until we've looked at the other places where we use format verbs like %q and %s on IPLD nodes. If you're going to just fix the one I found, that's perfectly fine, just don't close the issue yet :)

@smagdali
Copy link

smagdali commented Feb 4, 2022

assign to me?

also, any clues as to how can I trigger the error for test case?

@mvdan
Copy link
Contributor Author

mvdan commented Feb 4, 2022

You can create an ErrInvalidKey with the Key being a node from https://pkg.go.dev/github.com/ipld/go-ipld-prime/node/basicnode#NewString; I seem to recall that's how I got the bad formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good issue for new contributors
Projects
None yet
Development

No branches or pull requests

3 participants