{"record":{"id":"9bf306a9dc26f176","repo":"GoogleContainerTools/skaffold","slug":"writing-k8s-manifest-to-file-w","errorCode":null,"errorMessage":"writing k8s manifest to file: %w","messagePattern":"writing k8s manifest to file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/initializer/init.go","lineNumber":132,"sourceCode":"\tpipeline, err := yaml.Marshal(newConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif c.Opts.ConfigurationFile == \"-\" {\n\t\tout.Write(pipeline)\n\t\treturn nil\n\t}\n\n\tif !c.Force && !c.Opts.AutoInit {\n\t\tif done, err := prompt.WriteSkaffoldConfig(out, pipeline, newManifests, c.Opts.ConfigurationFile); done {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tfor path, manifest := range newManifests {\n\t\tif err = os.WriteFile(path, manifest, 0644); err != nil {\n\t\t\treturn fmt.Errorf(\"writing k8s manifest to file: %w\", err)\n\t\t}\n\t\tfmt.Fprintf(out, \"Generated manifest %s was written\\n\", path)\n\t}\n\n\tif c.Opts.AutoInit {\n\t\treturn nil\n\t}\n\n\tif err = os.WriteFile(c.Opts.ConfigurationFile, pipeline, 0644); err != nil {\n\t\treturn fmt.Errorf(\"writing config to file: %w\", err)\n\t}\n\n\tfmt.Fprintf(out, \"Configuration %s was written\\n\", c.Opts.ConfigurationFile)\n\ttips.PrintForInit(out, c.Opts)\n\n\treturn nil\n}\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/initializer/init.go#L114-L150","documentation":"When skaffold init finishes, WriteData writes any newly generated Kubernetes manifests to disk with os.WriteFile(path, manifest, 0644). If the write fails (unwritable directory, permission problem, path is a directory), the OS error is wrapped as 'writing k8s manifest to file'.","triggerScenarios":"DoInit/Transparent reach the manifest-writing loop and os.WriteFile fails for one of the generated manifest paths — directory doesn't exist, no write permission, path points to an existing directory, or the filesystem is read-only.","commonSituations":"init run in a read-only mounted repo; manifest target path conflicts with an existing directory of the same name; running without ownership of the project directory (sudo-created files); disk full.","solutions":["Check the wrapped OS error for the exact cause (ENOENT/EACCES/EISDIR)","Ensure the target directory exists and is writable (mkdir -p, chown/chmod)","Verify the path isn't a directory; remove or rename the conflicting entry","If the repo is read-only, run init in a writable checkout"],"exampleFix":"// before\nskaffold init   # manifests/target.yaml is a directory\n// after\nrm -rf manifests/target.yaml && mkdir -p manifests\nskaffold init","handlingStrategy":"validation","validationCode":"// pre-flight the manifest output paths before running init:\nfor _, p := range candidateManifestPaths {\n    if fi, err := os.Stat(p); err == nil && fi.IsDir() {\n        return fmt.Errorf(\"%s is a directory; init cannot write a manifest there\", p)\n    }\n    if err := os.WriteFile(p+\".writetest\", nil, 0o644); err != nil {\n        return fmt.Errorf(\"cannot write %s: %w\", p, err)\n    }\n    os.Remove(p + \".writetest\")\n}","typeGuard":null,"tryCatchPattern":"if err := initData.WriteData(out); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) {\n        return fmt.Errorf(\"init failed writing %s: check perms/dir (%v)\", pe.Path, pe.Err)\n    }\n    return err\n}","preventionTips":["Run init in a writable checkout, never on read-only mounts","Ensure manifest output directories exist before init","Avoid mixing sudo-created files with normal-user init runs"],"tags":["init","filesystem","manifests","file-write"],"backgroundTag":"file-write-permission-denied","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}