dagger/dagger · error

find go.work: %w

Error message

find go.work: %w

What it means

Wrap from syncModReplaceAndTidy when `go env GOWORK` fails in the module directory, i.e. the go toolchain could not be invoked to detect an active go.work file. Without this, replace-directive overrides cannot be synced safely.

Source

Thrown at cmd/codegen/generator/go/generate_module.go:284

	if err != nil {
		return nil, false, err
	}
	return &PackageInfo{
		// PackageName is unknown until we load the package
		PackageImport: path.Join(goMod.Module.Mod.Path, packageImport),

		DaggerPkgReplaced: isDaggerPkgCustomReplaced(goMod.Replace),
	}, needsRegen, nil
}

func (g *GoGenerator) syncModReplaceAndTidy(mod *modfile.File, genSt *generator.GeneratedState, modPath string) error {
	modDir := filepath.Join(g.Config.OutputDir, modPath)

	// if there is a go.work, we need to also set overrides there, otherwise
	// modules will have individually conflicting replace directives
	goWork, err := goEnv(modDir, "GOWORK")
	if err != nil {
		return fmt.Errorf("find go.work: %w", err)
	}

	// use Go SDK's embedded go.mod as basis for pinning versions
	sdkMod, err := modfile.Parse("go.mod", dagger.GoMod, nil)
	if err != nil {
		return fmt.Errorf("parse embedded go.mod: %w", err)
	}
	modRequires := make(map[string]*modfile.Require)
	for _, req := range mod.Require {
		modRequires[req.Mod.Path] = req
	}
	for _, minReq := range sdkMod.Require {
		// check if mod already at least this version
		if currentReq, ok := modRequires[minReq.Mod.Path]; ok {
			if semver.Compare(currentReq.Mod.Version, minReq.Mod.Version) >= 0 {
				continue
			}
		}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Verify a Go toolchain is installed and on PATH in the generation environment
  2. Run `go env GOWORK` manually in the module dir to see the failure
  3. Check GOFLAGS/GOCACHE settings that might break go env execution
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at cmd/codegen/generator/go/generate_module.go:284 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/0a6fafdd3c0d55b0. Report an issue: GitHub.