github/copilot-sdk · warning
failed to evaluate build constraints in
Error message
failed to evaluate build constraints in %q: %w
What it means
While scanning candidate .go files to detect the package name, detectPackageName calls buildContext.MatchFile to evaluate build constraints (build tags, GOOS/GOARCH fit). This error wraps any failure from that evaluation for a specific file, falling back to defaultPackageName.
Solutions
- Open the file named in the error and fix its //go:build / // +build constraint syntax.
- Remove or regenerate the offending file if it is generated or vestigial.
- Run `go vet ./...` on the directory to surface malformed build constraints.
- Ensure only one of //go:build and // +build is authoritative and they agree.
Example fix
// before (broken constraint in file.go) // +build linux amd64 //go:build linux && amd64 && // after //go:build linux && amd64 // +build linux,amd64
Defensive patterns
Strategy: try-catch
Try / catch
matches, err := buildContext.MatchFile(dir, name)
if err != nil {
log.Printf("skipping %s: bad build constraints: %v", filepath.Join(dir, name), err)
continue // or fix the file, depending on strictness
} Prevention
- Run `go vet ./...` to catch malformed //go:build lines early.
- Keep //go:build and // +build lines in agreement or drop the legacy form.
- Regenerate or remove corrupt/generated files with broken constraints.
When it happens
Trigger: A .go file in the package directory has malformed build constraints (e.g. malformed //go:build lines) that go/build cannot parse for the target platform, causing buildContext.MatchFile(dir, name) to return an error.
Common situations: Hand-edited or conflicting //go:build and // +build lines; non-UTF8 or corrupt files; generated files with broken constraint syntax; cross-compiling to a platform where constraint evaluation hits an unsupported combination.
Related errors
- failed to read package directory
- CreateSessionFSProvider is required in session config when…
- SessionFS capabilities declare SQLite support but the…
- invalid platform
- failed to get SDK version
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/7c8370be929ea574.
Report an issue: GitHub.
Appendix: source
Thrown at go/cmd/bundler/main.go:234
if err != nil {
return defaultPackageName, fmt.Errorf("failed to read package directory %q: %w", dir, err)
}
buildContext := build.Default
buildContext.GOOS = goos
buildContext.GOARCH = goarch
packageName := ""
for _, entry := range entries {
name := entry.Name()
if entry.IsDir() || !strings.HasSuffix(name, ".go") ||
strings.HasPrefix(name, ".") || strings.HasPrefix(name, "_") ||
strings.HasSuffix(name, "_test.go") || strings.HasPrefix(name, "zcopilot_") {
continue
}
matches, err := buildContext.MatchFile(dir, name)
if err != nil {
return defaultPackageName, fmt.Errorf("failed to evaluate build constraints in %q: %w", filepath.Join(dir, name), err)
}
if !matches {
continue
}
path := filepath.Join(dir, name)
file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.PackageClauseOnly)
if err != nil {
return defaultPackageName, fmt.Errorf("failed to parse package clause in %q: %w", path, err)
}
if packageName == "" {
packageName = file.Name.Name
continue
}
if packageName != file.Name.Name {
return defaultPackageName, fmt.Errorf("multiple packages %q and %q found in %q", packageName, file.Name.Name, dir)
}View on GitHub (pinned to cd8cf15dc3)