dagger / dagger

An engine to run your pipelines in containers

Home Page:https://dagger.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Re-exporting go module interfaces fail with unexpected error

jedevc opened this issue · comments

See https://github.com/jedevc/dagger-iface-issue. The issue is that the bar module cannot re-export FooCustomIface.

This should get caught on this error, something like this:

$ dagger -m github.com/jedevc/dagger-iface-issue/bar functions
Error: input: module.withSource.initialize resolve: failed to initialize module: failed to add object to module "bar": failed to validate type def: object "Bar" field "Custom" cannot reference external type from dependency module "foo"

However, instead we get an insane error:

$ dagger -m github.com/jedevc/dagger-iface-issue/bar functions
Error: query module objects: returned error 400 Bad Request: failed to get schema introspection JSON: introspection query failed: input: __schema.types[0].fields[0].type.ofType panic while resolving __Type.ofType: unknown type: BarFooCustomIface

goroutine 4384894 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x5e
github.com/dagger/dagger/dagql.(*Server).resolvePath.func1()
	/app/dagql/server.go:642 +0x74
panic({0x1b13200?, 0xc004eba2b0?})
	/usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/dagger/dagger/dagql/introspection.WrapTypeFromType(...)
	/app/dagql/introspection/types.go:476
github.com/dagger/dagger/dagql/introspection.(*Type).OfType(0xc00ad0d2f0)
	/app/dagql/introspection/types.go:629 +0x279
github.com/dagger/dagger/dagql/introspection.Install[...].func17({0xc007992440?, 0xc00ad0d2f0?, {0x0, 0x0, 0xc007bf8390, 0xc006229508}, 0x0}, {})
	/app/dagql/introspection/types.go:121 +0xaa
github.com/dagger/dagger/dagql.NodeFunc[...].func1({0xc007992440, 0xc00ad0d2f0, {0x0, 0x0, 0xc007bf8390, 0xc006229508}, 0x0}, 0xc0049e4120)
	/app/dagql/objects.go:354 +0x107
github.com/dagger/dagger/dagql.Class[...].Call(0x2312660?, {0x22e7118?, 0xc0049e40c0?}, {0xc007992440, 0xc00ad0d2f0, {0x0, 0x0, 0xc007bf8390, 0xc006229508}, 0x0}, ...)
	/app/dagql/objects.go:204 +0x15d
github.com/dagger/dagger/dagql.Instance[...].Select(0x2302160, {0x22e7118, 0xc0049e40c0}, {{0x202db6a, 0x6}, {0x322b040, 0x0, 0x0}, 0x0})
	/app/dagql/objects.go:270 +0x2fe
github.com/dagger/dagger/dagql.(*Server).cachedSelect.func1({0x22e7118?, 0xc0049e40c0?})
	/app/dagql/server.go:587 +0x12e
github.com/dagger/dagger/dagql.(*Server).cachedSelect(0xc00eaea960, {0x22e7150, 0xc00eaea910}, {0x22ea740, 0xc007992600}, {{0x202db6a, 0x6}, {0x322b040, 0x0, 0x0}, ...})
	/app/dagql/server.go:590 +0x1d8
github.com/dagger/dagger/dagql.(*Server).resolvePath(0x410a25?, {0x22e7150, 0xc00eaea910}, {0x22ea740?, 0xc007992600?}, {{0x202db6a, 0x6}, {{0x202db6a, 0x6}, {0x322b040, ...}, ...}, ...})
	/app/dagql/server.go:651 +0x13e
github.com/dagger/dagger/dagql.(*Server).Resolve.func1()
	/app/dagql/server.go:405 +0x7f
github.com/dagger/dagger/dagql.(*Server).Resolve.(*ErrorPool).Go.func3()
	/go/pkg/mod/github.com/sourcegraph/conc@v0.3.0/pool/error_pool.go:30 +0x22
github.com/sourcegraph/conc/pool.(*Pool).worker(0x22e7068?)
	/go/pkg/mod/github.com/sourcegraph/conc@v0.3.0/pool/pool.go:154 +0x6f
github.com/sourcegraph/conc/panics.(*Catcher).Try(0x445edc?, 0xc0112b2fd0?)
	/go/pkg/mod/github.com/sourcegraph/conc@v0.3.0/panics/panics.go:23 +0x48
github.com/sourcegraph/conc.(*WaitGroup).Go.func1()
	/go/pkg/mod/github.com/sourcegraph/conc@v0.3.0/waitgroup.go:32 +0x56
created by github.com/sourcegraph/conc.(*WaitGroup).Go in goroutine 4384855
	/go/pkg/mod/github.com/sourcegraph/conc@v0.3.0/waitgroup.go:30 +0x73

This is because our go codegen is actually wrong, and we construct the wrong typedef:

			WithObject(
				dag.TypeDef().WithObject("Bar").
					WithFunction(
						dag.Function("Hello",
							dag.TypeDef().WithKind(StringKind))).
					WithField("Custom", dag.TypeDef().WithObject("FooCustomIface"))), nil

Note the use of WithObject - this should instead be WithInterface. Because of this, we can't find FooCustomIface as a valid object, and so we attempt to namespace it twice, hence the bizarre error.


Not quite sure what the right answer is here:

  1. We could have objects degrade to interfaces at this point in the schema - since from a graphql perspective, they're just classes.
  2. We could have some better logic in the Go SDK to detect that the dagger interface (expressed as a golang struct) is actually an interface (but not immediately sure of a neat way to do this).