{"record":{"id":"3ce64016ae28be34","repo":"golangci/golangci-lint","slug":"can-t-create-file-s-w","errorCode":null,"errorMessage":"can't create file %s: %w","messagePattern":"can't create file (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/run.go","lineNumber":268,"sourceCode":"\tif err := c.runAndPrint(ctx); err != nil {\n\t\tc.log.Errorf(\"Running error: %s\", err)\n\t\tif c.exitCode == exitcodes.Success {\n\t\t\tif exitErr, ok := errors.AsType[*exitcodes.ExitError](err); ok {\n\t\t\t\tc.exitCode = exitErr.Code\n\t\t\t} else {\n\t\t\t\tc.exitCode = exitcodes.Failure\n\t\t\t}\n\t\t}\n\t}\n\n\tc.setupExitCode(ctx)\n}\n\nfunc (c *runCommand) startTracing() error {\n\tif c.opts.CPUProfilePath != \"\" {\n\t\tf, err := os.Create(c.opts.CPUProfilePath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't create file %s: %w\", c.opts.CPUProfilePath, err)\n\t\t}\n\t\tif err := pprof.StartCPUProfile(f); err != nil {\n\t\t\treturn fmt.Errorf(\"can't start CPU profiling: %w\", err)\n\t\t}\n\t}\n\n\tif c.opts.MemProfilePath != \"\" {\n\t\tif rate := os.Getenv(envMemProfileRate); rate != \"\" {\n\t\t\truntime.MemProfileRate, _ = strconv.Atoi(rate)\n\t\t}\n\t}\n\n\tif c.opts.TracePath != \"\" {\n\t\tf, err := os.Create(c.opts.TracePath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't create file %s: %w\", c.opts.TracePath, err)\n\t\t}\n\t\tif err = trace.Start(f); err != nil {","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L250-L286","documentation":"When CPU profiling is requested (--cpu-profile-path), `startTracing` creates the profile file with os.Create. If the file cannot be created, the error is wrapped as `can't create file %s: %w`. The path and underlying OS error are both included, so the cause is directly actionable.","triggerScenarios":"Passing --cpu-profile-path pointing to a non-existent directory, a path without write permission, or a path that is itself a directory; also disk-full or read-only filesystem conditions during os.Create.","commonSituations":"CI passing a profile path under a directory that was never created; typos in the path; running in a read-only container filesystem; permission mismatch when running the linter as a different user.","solutions":["Create the parent directory of the profile path before running (mkdir -p).","Point --cpu-profile-path at a writable location (e.g. /tmp/cpu.prof).","Fix permissions on the target directory (chmod/chown) or run as a user with write access.","Check the wrapped OS error after the message — 'no such file or directory' vs 'permission denied' vs 'is a directory' point to different fixes.","Free disk space if the error indicates the filesystem is full."],"exampleFix":"// before\n- run: golangci-lint run --cpu-profile-path=profiles/cpu.prof  # profiles/ missing\n// after\n- run: |\n    mkdir -p profiles\n    golangci-lint run --cpu-profile-path=profiles/cpu.prof","handlingStrategy":"validation","validationCode":"// verify the profile path's directory is writable before enabling profiling\nprofDir := filepath.Dir(cpuProfilePath)\nif err := os.MkdirAll(profDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot create profile dir %s: %w\", profDir, err)\n}","typeGuard":null,"tryCatchPattern":"f, err := os.Create(c.opts.CPUProfilePath)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) {\n        log.Printf(\"create failed: path=%s op=%s err=%v\", pe.Path, pe.Op, pe.Err)\n    }\n    return fmt.Errorf(\"can't create file %s: %w\", c.opts.CPUProfilePath, err)\n}","preventionTips":["mkdir -p the profile directory before passing --cpu-profile-path.","Use a simple writable path like /tmp/cpu.prof.","Don't point the flag at an existing directory.","Check permissions when the linter runs under a different user in CI."],"tags":["go","profiling","filesystem","cli"],"backgroundTag":"file-create-failed","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}