#Need help understanding an error when running `dagger develop`
1 messages · Page 1 of 1 (latest)
I found that this error happens when adding a context.Context field in the module's struct.
Steps to reproduce:
dagger init --sdk=go --source=.- edit the
type ModuleName structstruct to have acontext.Contextfield - run
dagger call container-echo --string-arg=isthisabug
package main
import (
"context"
"dagger/dagger-bug-minimal/internal/dagger"
)
type DaggerBugMinimal struct {
Context context.Context
}
// Returns a container that echoes whatever string argument is provided
func (m *DaggerBugMinimal) ContainerEcho(stringArg string) *dagger.Container {
return dag.Container().From("alpine:latest").WithExec([]string{"echo", stringArg})
}
// Returns lines that match a pattern in the files of the provided Directory
func (m *DaggerBugMinimal) GrepDir(ctx context.Context, directoryArg *dagger.Directory, pattern string) (string, error) {
return dag.Container().
From("alpine:latest").
WithMountedDirectory("/mnt", directoryArg).
WithWorkdir("/mnt").
WithExec([]string{"grep", "-R", pattern, "."}).
Stdout(ctx)
}
The output will be this:
Stderr:
Error: generate code: template: module.go.tmpl:85:3: executing "_dagger.gen.go/module.go.tmpl" at <ModuleMainSrc>: error calling ModuleMainSrc: cannot code-generate for foreign type Context
Hey! Yes, all the fields in your custom types should be serializable. Since context is an interface, that won't work