{"record":{"id":"5f9474cc4fdd49dc","repo":"kovidgoyal/kitty","slug":"failed-to-write-to-favorites-file-s-with-error","errorCode":null,"errorMessage":"Failed to write to favorites file %s with error: %w","messagePattern":"Failed to write to favorites file (.+?) with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/unicode_input/main.go","lineNumber":451,"sourceCode":"\t\tevent.Handled = true\n\t\texe, err := os.Executable()\n\t\tif err != nil {\n\t\t\tself.err = err\n\t\t\tself.lp.Quit(1)\n\t\t\treturn\n\t\t}\n\t\tfp := favorites_path()\n\t\tif len(load_favorites(false)) == 0 || !favorites_loaded_from_user_config {\n\t\t\traw := serialize_favorites(load_favorites(false))\n\t\t\terr = os.MkdirAll(filepath.Dir(fp), 0o755)\n\t\t\tif err != nil {\n\t\t\t\tself.err = fmt.Errorf(\"Failed to create config directory to store favorites in: %w\", err)\n\t\t\t\tself.lp.Quit(1)\n\t\t\t\treturn\n\t\t\t}\n\t\t\terr = utils.AtomicUpdateFile(fp, bytes.NewReader(utils.UnsafeStringToBytes(raw)), 0o600)\n\t\t\tif err != nil {\n\t\t\t\tself.err = fmt.Errorf(\"Failed to write to favorites file %s with error: %w\", fp, err)\n\t\t\t\tself.lp.Quit(1)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\terr = self.lp.SuspendAndRun(func() error {\n\t\t\tcmd := exec.Command(exe, \"edit-in-kitty\", \"--type=overlay\", fp)\n\t\t\tcmd.Stdin = os.Stdin\n\t\t\tcmd.Stdout = os.Stdout\n\t\t\tcmd.Stderr = os.Stderr\n\t\t\terr = cmd.Run()\n\t\t\tif err == nil {\n\t\t\t\tload_favorites(true)\n\t\t\t} else {\n\t\t\t\tfmt.Fprintln(os.Stderr, err)\n\t\t\t\tfmt.Fprintln(os.Stderr, \"Failed to run edit-in-kitty, favorites have not been changed. Press Enter to continue.\")\n\t\t\t\tvar ln string\n\t\t\t\tfmt.Scanln(&ln)\n\t\t\t}","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/unicode_input/main.go#L433-L469","documentation":"After ensuring the config directory exists, the unicode_input kitten writes the serialized favorites JSON atomically via utils.AtomicUpdateFile with mode 0600. If that write fails (disk full, permission denied, favorites.json is a directory or owned by another user), the kitten stores this error and exits with code 1.","triggerScenarios":"Pressing the favorites key in the unicode input kitten when the favorites file path is unwritable — favorites.json owned by root, read-only mount, or I/O errors during the atomic rename/temp file creation.","commonSituations":"Previously ran kitty with sudo so ~/.config/kitty/unicode_input/favorites.json is root-owned; disk quota exhausted; the favorites file was replaced by a directory; synced/dropbox-held config dirs with transient lock issues.","solutions":["Fix ownership: sudo chown -R $USER ~/.config/kitty","Check disk space and quota: df -h ~","If favorites.json is a directory or corrupt, remove it: rm -rf ~/.config/kitty/unicode_input/favorites.json (it will be recreated)","On read-only setups, pre-create a writable config dir and point XDG_CONFIG_HOME at it"],"exampleFix":"# before\n$ ls -l ~/.config/kitty/unicode_input/favorites.json\n-rw------- 1 root root ... favorites.json\n\n# after\n$ sudo chown $USER:$USER ~/.config/kitty/unicode_input/favorites.json","handlingStrategy":"try-catch","validationCode":"fp := favorites_path()\nif _, err := os.Stat(fp); err == nil {\n    if info, _ := os.Stat(fp); info != nil && !info.Mode().IsRegular() {\n        return fmt.Errorf(\"favorites path %s is not a regular file\", fp)\n    }\n    if err := os.Chmod(fp, 0o600); err != nil {\n        return fmt.Errorf(\"favorites file not writable: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := utils.AtomicUpdateFile(fp, bytes.NewReader(raw), 0o600); err != nil {\n    log.Printf(\"could not save favorites to %s: %v (continuing)\", fp, err)\n}","preventionTips":["chown -R $USER ~/.config after any sudo usage","Monitor disk space on $HOME","Treat favorites persistence as best-effort; degrade gracefully"],"tags":["kitty","unicode-input","filesystem","write-error","favorites"],"backgroundTag":"file-write-permission-denied","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}