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

Using ArrayOf in MediaType→Attributes→Attribute causes generator crash #990

Closed
danderson opened this Issue Dec 26, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@danderson

danderson commented Dec 26, 2016

I have a DSL that causes a nil pointer dereference crash when running goagen. This is not an ideal way of telling me I made a mistake :P. Minimal repro design:

package design

import (
	. "github.com/goadesign/goa/design"
	. "github.com/goadesign/goa/design/apidsl"
)

var _ = API("crash", func() {})

var _ = MediaType("thing", func() {
	Attributes(func() {
		Attribute("rec", ArrayOf("thing"))
	})

	View("default", func() {
		Attribute("rec")
	})
})

The error in this design is that I should have used CollectionOf, not ArrayOf.

Running goagen bootstrap on this design results in a nil pointer dereference crash:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4a37e2]

goroutine 1 [running]:
panic(0x795780, 0xc4200100e0)
	/usr/lib/go/src/runtime/panic.go:500 +0x1a1
github.com/goadesign/goa/design.(*UserTypeDefinition).IsPrimitive(0x0, 0xc420163670)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/types.go:642 +0x22
github.com/goadesign/goa/design.(*AttributeDefinition).Validate(0xc42018be80, 0xc420163680, 0xf, 0x9ebd60, 0xc42018bf00, 0xc420163670)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:451 +0x139
github.com/goadesign/goa/design.(*AttributeDefinition).Validate(0xc42018bf00, 0xc420163670, 0xc, 0x9ebfe0, 0xc420168e80, 0xc420163660)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:484 +0x982
github.com/goadesign/goa/design.(*AttributeDefinition).Validate(0xc42018bd80, 0x0, 0x0, 0x9ebfe0, 0xc420168e80, 0xc41fff4d49)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:479 +0x451
github.com/goadesign/goa/design.(*UserTypeDefinition).Validate(0xc420168e80, 0x0, 0x0, 0x9ebea0, 0xc42016f3c0, 0x40f69e)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:520 +0xa8
github.com/goadesign/goa/design.(*MediaTypeDefinition).Validate(0xc42016f3c0, 0x9f13a0)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:528 +0xa6
github.com/goadesign/goa/design.(*APIDefinition).Validate.func2(0xc42016f3c0, 0xc4201c6510, 0xc4201634c0)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:146 +0x49
github.com/goadesign/goa/design.(*APIDefinition).IterateMediaTypes(0xc4201922c0, 0xc42020f9d8, 0x0, 0x0)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/definitions.go:528 +0x1d8
github.com/goadesign/goa/design.(*APIDefinition).Validate(0xc4201922c0, 0x9ebce0, 0xc4201922c0)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/validation.go:148 +0x333
github.com/goadesign/goa/dslengine.validateSet(0xc420163610, 0x1, 0x1, 0xa2b908, 0x0)
	/home/dave/hack/go/src/github.com/goadesign/goa/dslengine/runner.go:312 +0x120
github.com/goadesign/goa/design.(*APIDefinition).IterateSets(0xc4201922c0, 0x84ca30)
	/home/dave/hack/go/src/github.com/goadesign/goa/design/definitions.go:458 +0x96
github.com/goadesign/goa/dslengine.Run(0x9ed460, 0xc420168ea0)
	/home/dave/hack/go/src/github.com/goadesign/goa/dslengine/runner.go:108 +0x197
main.main()
	/home/dave/hack/go/src/go.universe.tf/gipam/goagen171272070/main.go:24 +0x63
@raphael

This comment has been minimized.

Show comment
Hide comment
@raphael

raphael Dec 28, 2016

Member

Thanks for the report. It's actually legal to use ArrayOf on a media type - unusual but legal. The difference between CollectionOf and ArrayOf is in what they produce (media type vs. user type) - not in what they accept as parameter.

Member

raphael commented Dec 28, 2016

Thanks for the report. It's actually legal to use ArrayOf on a media type - unusual but legal. The difference between CollectionOf and ArrayOf is in what they produce (media type vs. user type) - not in what they accept as parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment