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

bindnode cannot infer schemas with links #321

Closed
aschmahmann opened this issue Dec 27, 2021 · 1 comment · Fixed by #432
Closed

bindnode cannot infer schemas with links #321

aschmahmann opened this issue Dec 27, 2021 · 1 comment · Fixed by #432
Assignees

Comments

@aschmahmann
Copy link

aschmahmann commented Dec 27, 2021

bindnode currently cannot infer schemas with links in them such as:

type Node struct {
   Next cidlink.Link
}

next := &Node{ Next: nextCid }
node := bindnode.Wrap(next, nil)

It will error with:

panic: duplicate type name: Link [recovered]
	panic: duplicate type name: Link

goroutine 55 [running]:
testing.tRunner.func1.2({0x18ccd60, 0xc000095f20})
	C:/Go/go1.17.5/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	C:/Go/go1.17.5/src/testing/testing.go:1212 +0x218
panic({0x18ccd60, 0xc000095f20})
	C:/Go/go1.17.5/src/runtime/panic.go:1038 +0x215
github.com/ipld/go-ipld-prime/schema.(*TypeSystem).Accumulate(0x28424e0, {0x1e4c498, 0xc0000a4be0})
	C:/Users/adin/go/pkg/mod/github.com/ipld/go-ipld-prime@v0.14.4-0.20211217152141-008fd70fc96f/schema/tmpBuilders.go:151 +0x1b4
github.com/ipld/go-ipld-prime/node/bindnode.inferSchema({0x1e6db40, 0x1a3a1c0})
	C:/Users/adin/go/pkg/mod/github.com/ipld/go-ipld-prime@v0.14.4-0.20211217152141-008fd70fc96f/node/bindnode/infer.go:318 +0x5f3
github.com/ipld/go-ipld-prime/node/bindnode.inferSchema({0x1e6db40, 0x1996140})
	C:/Users/adin/go/pkg/mod/github.com/ipld/go-ipld-prime@v0.14.4-0.20211217152141-008fd70fc96f/node/bindnode/infer.go:303 +0x468
github.com/ipld/go-ipld-prime/node/bindnode.Wrap({0x189f960, 0xc000258090}, {0x0, 0x0})
	C:/Users/adin/go/pkg/mod/github.com/ipld/go-ipld-prime@v0.14.4-0.20211217152141-008fd70fc96f/node/bindnode/api.go:79 +0x1d9
...

What's going on is that inferSchema

func inferSchema(typ reflect.Type) schema.Type {
doesn't have any concept of Links.

We do have some types predefined already for what a Link could reasonably be, although we can also try interface detection to see if something fulfills the interface for an IPLD link. The ones we already have defined are

goTypeLink = reflect.TypeOf((*datamodel.Link)(nil)).Elem()
goTypeCidLink = reflect.TypeOf((*cidlink.Link)(nil)).Elem()
goTypeCid = reflect.TypeOf((*cid.Cid)(nil)).Elem()

@mvdan mvdan self-assigned this Jan 20, 2022
@mvdan
Copy link
Contributor

mvdan commented Jan 20, 2022

Thanks for reporting - I'll fix this soon.

@mvdan mvdan removed their assignment Mar 23, 2022
rvagg added a commit that referenced this issue May 24, 2022
@rvagg rvagg self-assigned this May 24, 2022
rvagg added a commit that referenced this issue Jun 1, 2022
@rvagg rvagg closed this as completed in #432 Jun 1, 2022
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.

3 participants