github/copilot-sdk · error

failed to add zstd dependency

Error message

failed to add zstd dependency: %w
%s

What it means

ensureZstdDependency runs 'go mod tidy' so the generated module depends on the zstd package needed by generated code. If the tidy command exits non-zero, the error plus the combined command output are wrapped with this message. It indicates the module's go.mod/go.sum could not be reconciled.

Solutions

  1. Run 'go mod tidy' manually in the module dir and read the combined output appended to the error
  2. Confirm 'go' is installed and on PATH, and the toolchain version satisfies the go.mod go directive
  3. Check network/proxy access: GOPROXY, GOPRIVATE, and any private-repo auth for module downloads
  4. If go.sum/go.mod is corrupted, restore from VCS or run 'go mod download' then 'go mod tidy'
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure go is available before bundling
if _, err := exec.LookPath("go"); err != nil { return errors.New("go toolchain required on PATH") }

Try / catch

// Go
if err := ensureZstdDependency(); err != nil {
	log.Fatalf("zstd dependency step failed: %v — inspect 'go mod tidy' output above", err)
}

Prevention

When it happens

Trigger: Running the bundler's dependency step when 'go mod tidy' fails: go not on PATH, missing or corrupt go.mod/go.sum, network failure fetching modules, conflicting requirements, or a Go toolchain version mismatch (go directive newer than installed toolchain).

Common situations: Offline CI runner with no module proxy access; private module requiring credentials; go.mod edited by hand leaving unsatisfiable requires; GOPROXY misconfigured; running with an older Go than the module requires.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/685fb0e928ca310f. Report an issue: GitHub.

Appendix: source

Thrown at go/cmd/bundler/main.go:1279

	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	h := sha256.New()
	if _, err := io.Copy(h, file); err != nil {
		return nil, err
	}
	return h.Sum(nil), nil
}

// ensureZstdDependency makes sure the module has the zstd dependency for generated code.
func ensureZstdDependency() error {
	cmd := exec.Command("go", "mod", "tidy")
	output, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("failed to add zstd dependency: %w\n%s", err, strings.TrimSpace(string(output)))
	}
	return nil
}

// checkEmbeddedVersion checks if an embedded CLI version exists and compares it with the detected version.
func checkEmbeddedVersion(detectedVersion, goos, goarch, outputDir string) error {
	// Look for the generated Go file for this platform
	goFileName := fmt.Sprintf("zcopilot_%s_%s.go", goos, goarch)
	goFilePath := filepath.Join(outputDir, goFileName)

	data, err := os.ReadFile(goFilePath)
	if err != nil {
		if os.IsNotExist(err) {
			// No existing embedded version, nothing to check
			return nil
		}
		return fmt.Errorf("failed to read existing Go file: %w", err)
	}

View on GitHub (pinned to cd8cf15dc3)