{"record":{"id":"fed48d6c4bdcdab1","repo":"golangci/golangci-lint","slug":"writing-file-s-w","errorCode":null,"errorMessage":"writing file %s: %w","messagePattern":"writing file (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/internal/migrate/cloner/cloner.go","lineNumber":191,"sourceCode":"\n\terr := printer.Fprint(&buf, fset, file)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"printing %s: %w\", srcPath, err)\n\t}\n\n\tdstPath := filepath.Join(dstDir, filepath.Base(srcPath))\n\n\t_ = os.MkdirAll(filepath.Dir(dstPath), os.ModePerm)\n\n\tformatted, err := imports.Process(dstPath, buf.Bytes(), nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"formatting %s: %w\", dstPath, err)\n\t}\n\n\t//nolint:gosec,mnd // The permission is right.\n\terr = os.WriteFile(dstPath, formatted, 0o644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"writing file %s: %w\", dstPath, err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":173,"sourceCodeEnd":196,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/internal/migrate/cloner/cloner.go#L173-L196","documentation":"This error is returned by writeNewFile in the migrate cloner when os.WriteFile fails to persist the formatted cloned configuration file to dstPath. The clone step of `golangci-lint migrate` copies and re-formats the old configuration, and any filesystem-level failure during the write is wrapped with the destination path for context. It indicates the migration aborted because the output file could not be written.","triggerScenarios":"os.WriteFile(dstPath, formatted, 0o644) returns an error: destination directory does not exist, read-only filesystem, permission denied, disk full, or dstPath is a directory.","commonSituations":"Running migrate in a read-only checkout, a directory owned by another user, a full disk (especially CI runners), or when the target output path collides with an existing directory.","solutions":["Check that the parent directory of the destination file exists and is writable by the current user.","Free disk space and re-run the migrate command.","If the path is a directory or locked by another process, choose a different output path or close the locking process.","Re-run with elevated permissions only if the target location genuinely requires them."],"exampleFix":"// before\nerr = os.WriteFile(dstPath, formatted, 0o644)\n// after\nif err := os.MkdirAll(filepath.Dir(dstPath), 0o755); err != nil {\n    return fmt.Errorf(\"creating dir for %s: %w\", dstPath, err)\n}\nif err := os.WriteFile(dstPath, formatted, 0o644); err != nil {\n    return fmt.Errorf(\"writing file %s: %w\", dstPath, err)\n}","handlingStrategy":"try-catch","validationCode":"if err := os.MkdirAll(filepath.Dir(dstPath), 0o755); err != nil { return err }\nif fi, err := os.Stat(dstPath); err == nil && fi.IsDir() { return fmt.Errorf(\"%s is a directory\", dstPath) }","typeGuard":null,"tryCatchPattern":"if err := writeNewFile(dstPath, srcPath); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.EACCES) {\n        // handle permission problem on dstPath\n    }\n    return err\n}","preventionTips":["Ensure the destination directory exists and is writable before running migrate.","Watch free disk space in CI runners.","Never point the migrate output at an existing directory."],"tags":["go","filesystem","config-migration","file-write"],"backgroundTag":"file-write-permission-denied","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}