{"record":{"id":"5c45259f478a65ad","repo":"golangci/golangci-lint","slug":"open-source-file-w","errorCode":null,"errorMessage":"open source file: %w","messagePattern":"open source file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/builder.go","lineNumber":212,"sourceCode":"\t)\n\tcmd.Dir = b.repo\n\n\toutput, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\tb.log.Warnf(\"%s\", string(output))\n\n\t\treturn fmt.Errorf(\"%s: %w\", strings.Join(cmd.Args, \" \"), err)\n\t}\n\n\treturn nil\n}\n\nfunc (b Builder) copyBinary(binaryName string) error {\n\tsrc := filepath.Join(b.repo, binaryName)\n\n\tsource, err := os.Open(filepath.Clean(src))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open source file: %w\", err)\n\t}\n\n\tdefer func() { _ = source.Close() }()\n\n\tinfo, err := source.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"stat source file: %w\", err)\n\t}\n\n\tif b.cfg.Destination != \"\" {\n\t\terr = os.MkdirAll(b.cfg.Destination, os.ModePerm)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"create destination directory: %w\", err)\n\t\t}\n\t}\n\n\tdst, err := os.OpenFile(filepath.Join(b.cfg.Destination, binaryName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, info.Mode())\n\tif err != nil {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/builder.go#L194-L230","documentation":"copyBinary wraps the error from os.Open of the built binary inside the repo directory (filepath.Join(b.repo, binaryName), cleaned via filepath.Clean). The %w preserves the underlying *os.PathError (e.g. ENOENT, EACCES). It means the builder could not open the compiled artifact for reading before copying it to the destination.","triggerScenarios":"Builder.Build ran go build successfully (or skipped it) but os.Open(b.repo/<binaryName>) failed: the binary was not produced at the expected path, binaryName from getBinaryName() does not match the actual output file, the file was deleted between build and copy, or the process lacks read permission.","commonSituations":"go build output name differs from getBinaryName() (e.g. GOOS/GOARCH suffix added by -o or goreleaser-style naming), building in a dirty CI checkout where the artifact is elsewhere, repo path misconfigured so src points at a nonexistent directory, or read permissions stripped on the artifact.","solutions":["Verify the built binary exists at filepath.Join(b.repo, binaryName) — run ls on that exact path after the build step","Confirm getBinaryName() returns the same filename go build was told to produce (-o flag), including any GOOS/GOARCH prefixes","Check the b.repo configuration points at the directory containing the artifact","Check file permissions on the binary (chmod +r) and that the user running the build can read it","Inspect the wrapped *os.PathError in the message to distinguish not-found (ENOENT) from permission (EACCES)"],"exampleFix":"// before\ngo build ./cmd/tool\n// after\ngo build -o tool ./cmd/tool  # ensure output name matches binaryName used by copyBinary","handlingStrategy":"validation","validationCode":"src := filepath.Join(repo, binaryName)\nif info, err := os.Stat(src); err != nil {\n    return fmt.Errorf(\"binary %s missing before copy: %w\", src, err)\n} else if info.IsDir() {\n    return fmt.Errorf(\"%s is a directory, expected a binary\", src)\n}","typeGuard":null,"tryCatchPattern":"if err := b.copyBinary(name); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr, fs.ErrNotExist) {\n        log.Fatalf(\"built binary not found at %s: rebuild with the correct -o output name\", perr.Path)\n    }\n    return err\n}","preventionTips":["Make go build emit exactly the filename getBinaryName() expects (explicit -o)","After the build step, assert the artifact exists before copying","Pin and verify b.repo points at the build output directory","In CI, archive the artifact immediately to avoid later-stage cleanup races"],"tags":["go","file-io","build","enoent"],"backgroundTag":"file-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}