#Need help understanding an error when running `dagger develop`

1 messages · Page 1 of 1 (latest)

weary totem
#

Running dagger develop results in the following error:

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

Is this something I caused with my code ?

weary totem
#

I found that this error happens when adding a context.Context field in the module's struct.

Steps to reproduce:

  1. dagger init --sdk=go --source=.
  2. edit the type ModuleName struct struct to have a context.Context field
  3. 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
olive widget
#

Hey! Yes, all the fields in your custom types should be serializable. Since context is an interface, that won't work