{"record":{"id":"1f26f27b40de5778","repo":"abiosoft/colima","slug":"error-writing-yaml-file-w","errorCode":null,"errorMessage":"error writing yaml file: %w","messagePattern":"error writing yaml file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/yamlutil/yaml.go","lineNumber":33,"sourceCode":"\n// WriteYAML encodes struct to file as YAML.\nfunc WriteYAML(value any, file string) error {\n\tb, err := yaml.Marshal(value)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error encoding YAML: %w\", err)\n\t}\n\n\treturn os.WriteFile(file, b, 0644)\n}\n\n// Save saves the config.\nfunc Save(c config.Config, file string) error {\n\tb, err := encodeYAML(c)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := os.WriteFile(file, b, 0644); err != nil {\n\t\treturn fmt.Errorf(\"error writing yaml file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc encodeYAML(conf config.Config) ([]byte, error) {\n\tvar doc yaml.Node\n\n\tf, err := embedded.Read(\"defaults/colima.yaml\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error reading config file: %w\", err)\n\t}\n\n\tif err := yaml.Unmarshal(f, &doc); err != nil {\n\t\treturn nil, fmt.Errorf(\"embedded default config is invalid yaml: %w\", err)\n\t}\n\n\tif l := len(doc.Content); l != 1 {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/util/yamlutil/yaml.go#L15-L51","documentation":"Save (util/yamlutil/yaml.go:33) writes the encoded config to disk with os.WriteFile and wraps I/O failures. The encode step already succeeded, so the failure is at the filesystem layer: permission denied on the target (usually under ~/.colima or the profile dir), a missing parent directory, a read-only filesystem, or a full disk. colima writes its state and the Lima override YAML through this path during start/stop.","triggerScenarios":"A previous `sudo colima ...` run left root-owned files in ~/.colima, so the next non-root save gets EACCES; disk full (ENOSPC); the profile directory was deleted mid-operation; the config dir is on a read-only mount.","commonSituations":"Mixing sudo and non-sudo colima invocations — the single most common cause; macOS disk nearly full; migration/restore of the home directory that changed ownership; security tools blocking writes to dotfile dirs.","solutions":["Fix ownership of colima state: `sudo chown -R $(id -u):$(id -g) ~/.colima` and retry","Free disk space or move large files off the volume holding ~/.colima","Recreate the missing profile dir (e.g. `mkdir -p ~/.colima/_lima/default`) or `colima delete` then start fresh","Never run colima with sudo unless you will always run it that way"],"exampleFix":"# before\n$ colima start\nerror writing yaml file: open /Users/me/.colima/_lima/default/colima.yaml: permission denied\n\n# after\n$ sudo chown -R $(id -u):$(id -g) ~/.colima\n$ colima start","handlingStrategy":"validation","validationCode":"// probe writability of the config dir before saving\nfunc dirWritable(dir string) error {\n    f, err := os.OpenFile(filepath.Join(dir, \".probe\"), os.O_CREATE|os.O_WRONLY, 0o644)\n    if err != nil { return fmt.Errorf(\"%s not writable (permissions? disk full?): %w\", dir, err) }\n    _ = f.Close()\n    return os.Remove(filepath.Join(dir, \".probe\"))\n}","typeGuard":"func isPermissionErr(err error) bool {\n    return errors.Is(err, os.ErrPermission) || strings.HasSuffix(err.Error(), \"permission denied\")\n}","tryCatchPattern":"if err := util.Save(cfg, file); err != nil {\n    if isPermissionErr(err) {\n        // guide the user to the sudo-ownership fix instead of a generic failure\n        return fmt.Errorf(\"%w — fix with: sudo chown -R $(id -u):$(id -g) ~/.colima\", err)\n    }\n    return err\n}","preventionTips":["Never mix sudo and non-sudo colima runs on the same profile","Check disk space before start on space-constrained machines","After any sudo run, chown ~/.colima back to your user","Keep ~/.colima on the local (non-read-only) volume"],"tags":["yaml","filesystem","permissions","disk-full"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}