plandex-ai/plandex · error
error writing file: %v
Error message
error writing file: %v
What it means
WriteCustomModelsFile calls os.WriteFile(path, jsonData, 0644) to persist custom-models.json. This error wraps the OS-level failure of that write — the JSON marshal already succeeded, so the problem is filesystem access or path validity at the Plandex home accounts directory.
Source
Thrown at app/cli/lib/custom_models.go:151
}
func WriteCustomModelsFile(path string, modelsInput *shared.ModelsInput) error {
err := os.MkdirAll(filepath.Dir(path), 0755)
if err != nil {
return fmt.Errorf("error creating directory: %v", err)
}
clientModelsInput := modelsInput.ToClientModelsInput()
clientModelsInput.PrepareUpdate()
jsonData, err := json.MarshalIndent(clientModelsInput, "", " ")
if err != nil {
return fmt.Errorf("error marshalling models: %v", err)
}
err = os.WriteFile(path, jsonData, 0644)
if err != nil {
return fmt.Errorf("error writing file: %v", err)
}
err = SaveCustomModelsHash(path, modelsInput)
if err != nil {
return fmt.Errorf("error saving hash file: %v", err)
}
return nil
}
func SaveCustomModelsHash(basePath string, modelsInput *shared.ModelsInput) error {
hashPath := basePath + ".hash"
hash, err := modelsInput.Hash()
if err != nil {
return fmt.Errorf("error hashing models: %v", err)
}
View on GitHub (pinned to e2d772072e)
Solutions
- Check the wrapped error for 'permission denied' and fix ownership/permissions on ~/.plandex/accounts/<userId>/ (e.g. chown -R $USER ~/.plandex).
- Verify free disk space (df -h) and clear space if the disk is full.
- Ensure the accounts/<userId> directory exists; recreate it if it was deleted.
- Avoid running the CLI as root/sudo, which creates root-owned files in the Plandex home dir.
Example fix
// before sudo plandex models # creates root-owned custom-models.json // after chown -R $(whoami) ~/.plandex plandex models
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate writability before calling
import "os"
func canWrite(path string) bool {
dir := filepath.Dir(path)
if _, err := os.Stat(dir); err != nil { return false }
f, err := os.CreateTemp(dir, ".wtest")
if err != nil { return false }
f.Close(); os.Remove(f.Name())
return true
}
// if !canWrite(path) { fix permissions/space first } Type guard
func isWriteError(err error) bool {
return err != nil && strings.Contains(err.Error(), "error writing file") &&
!strings.Contains(err.Error(), "hash")
} Try / catch
if err := lib.WriteCustomModelsFile(path, input); err != nil {
if isWriteError(err) {
term.Error("Cannot write custom-models.json: " + err.Error())
// surface os.* permission/disk hint to the user
return
}
return err
} Prevention
- Check disk space (df -h) in environments running the CLI unattended.
- Never run the CLI with sudo; it creates root-owned files under ~/.plandex.
- Ensure ~/.plandex/accounts/<userId>/ exists and is writable by the current user.
- Monitor for read-only remounts on NFS/network home directories.
When it happens
Trigger: os.WriteFile failing because the target directory (~/.plandex/accounts/<userId>/) does not exist, the disk is full, permissions on the file/directory deny writing, or the path points somewhere unwritable.
Common situations: Read-only home directory or NFS mount; disk quota exceeded; custom-models.json owned by another user after running the CLI with sudo; accounts directory deleted manually.
Understand the failure class
Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.
Related errors
- failed to write %s: %s
- error writing hash file: %v
- error writing JSON file: %v
- error walking directory: %s
- failed to check if %s exists: %s
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/21d2f99d20aacabd.
Report an issue: GitHub.