{"record":{"id":"c0150e9a5effc1de","repo":"golangci/golangci-lint","slug":"create-temporary-directory-w","errorCode":null,"errorMessage":"create temporary directory: %w","messagePattern":"create temporary directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/custom.go","lineNumber":88,"sourceCode":"\n\tif c.opts.destination != \"\" {\n\t\tcfg.Destination = c.opts.destination\n\t}\n\n\terr = cfg.Validate()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tc.cfg = cfg\n\n\treturn nil\n}\n\nfunc (c *customCommand) runE(cmd *cobra.Command, _ []string) error {\n\ttmp, err := os.MkdirTemp(os.TempDir(), \"custom-gcl\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create temporary directory: %w\", err)\n\t}\n\n\tdefer func() {\n\t\tif os.Getenv(envKeepTempFiles) != \"\" {\n\t\t\tlog.Printf(\"WARN: The env var %s has been detected: the temporary directory is preserved: %s\", envKeepTempFiles, tmp)\n\n\t\t\treturn\n\t\t}\n\n\t\t_ = os.RemoveAll(tmp)\n\t}()\n\n\terr = internal.NewBuilder(c.log, c.cfg, tmp).Build(cmd.Context())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"build process: %w\", err)\n\t}\n\n\treturn nil","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/custom.go#L70-L106","documentation":"customCommand.runE builds a custom golangci-lint binary and first creates a temporary working directory with os.MkdirTemp(os.TempDir(), \"custom-gcl\"). If directory creation fails, the error is wrapped as \"create temporary directory: %w\". The temp dir is normally cleaned up afterwards unless the keep-temp-files env var is set.","triggerScenarios":"os.MkdirTemp(os.TempDir(), \"custom-gcl\") fails while running the custom subcommand — TMPDIR points to a nonexistent/unwritable location, disk full, or too many open files.","commonSituations":"TMPDIR env var set to an invalid path in CI; read-only /tmp in containers; disk quota exceeded; SELinux/AppArmor blocking writes to the temp dir; /tmp filled by prior failed builds.","solutions":["Check the wrapped %w error (os.PathError) for the path and errno (ENOENT, EACCES, ENOSPC)","Verify/set TMPDIR to an existing writable directory (echo $TMPDIR; mkdir -p $TMPDIR)","Free disk space if the error is 'no space left on device'","In restricted containers, ensure /tmp (or $TMPDIR) is mounted writable","Clear out leftover custom-gcl* directories if /tmp is cluttered"],"exampleFix":"// before (CI)\nTMPDIR=/nonexistent golangci-lint custom\n// create temporary directory: mkdir /nonexistent/custom-gcl...: no such file or directory\n\n// after\nexport TMPDIR=$(mktemp -d)\ngolangci-lint custom","handlingStrategy":"fallback","validationCode":"tmpBase := os.TempDir()\nif info, err := os.Stat(tmpBase); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"temp dir %s unusable (check TMPDIR)\", tmpBase)\n}\nprobe, err := os.CreateTemp(tmpBase, \"write-probe\")\nif err != nil {\n    return fmt.Errorf(\"temp dir %s not writable: %w\", tmpBase, err)\n}\n_ = os.Remove(probe.Name())\n_ = probe.Close()","typeGuard":"func isMkdirTempError(err error) (string, bool) {\n    var pe *os.PathError\n    if errors.As(err, &pe) {\n        return pe.Path, true\n    }\n    return \"\", false\n}","tryCatchPattern":"tmp, err := os.MkdirTemp(os.TempDir(), \"custom-gcl\")\nif err != nil {\n    if errors.Is(err, fs.ErrPermission) || errors.Is(err, syscall.ENOSPC) {\n        return fmt.Errorf(\"fix TMPDIR or free disk space: %w\", err)\n    }\n    return fmt.Errorf(\"create temporary directory: %w\", err)\n}","preventionTips":["Ensure TMPDIR points to an existing writable directory, especially in CI and containers","Monitor disk space; temp-based builds fail fast when the disk fills","Clean leftover custom-gcl* directories periodically","In hardened environments, whitelist the temp dir for writes (SELinux/AppArmor)"],"tags":["filesystem","tempdir","build"],"backgroundTag":"temp-dir-creation-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}