{"record":{"id":"6be9fc8b2854f899","repo":"kovidgoyal/kitty","slug":"failed-to-get-the-current-working-directory-with-e","errorCode":null,"errorMessage":"Failed to get the current working directory with error: %w","messagePattern":"Failed to get the current working directory with error: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/cmd/edit_in_kitty/main.go","lineNumber":217,"sourceCode":"\tdata := strings.Builder{}\n\tdata.Grow(len(file_data) * 4)\n\n\tadd := func(key, val string) {\n\t\tif data.Len() > 0 {\n\t\t\tdata.WriteString(\",\")\n\t\t}\n\t\tdata.WriteString(key)\n\t\tdata.WriteString(\"=\")\n\t\tdata.WriteString(val)\n\t}\n\tadd_encoded := func(key, val string) { add(key, encode(val)) }\n\n\tif unix.Access(path, unix.R_OK|unix.W_OK) != nil {\n\t\treturn 1, fmt.Errorf(\"%s is not readable and writeable\", path)\n\t}\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn 1, fmt.Errorf(\"Failed to get the current working directory with error: %w\", err)\n\t}\n\tadd_encoded(\"cwd\", cwd)\n\tfor _, arg := range os.Args[2:] {\n\t\tadd_encoded(\"a\", arg)\n\t}\n\tadd(\"file_inode\", fmt.Sprintf(\"%d:%d:%d\", s.Dev, s.Ino, s.Mtim.Nano()))\n\tadd_encoded(\"file_data\", utils.UnsafeBytesToString(file_data))\n\tfmt.Println(\"Waiting for editing to be completed, press Esc to abort...\")\n\twrite_data := func(data_type string, rdata []byte) (err error) {\n\t\terr = utils.AtomicWriteFile(path, bytes.NewReader(rdata), fs.FileMode(s.Mode).Perm())\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"Failed to write data to %s with error: %w\", path, err)\n\t\t}\n\t\treturn\n\t}\n\texit_code, err = edit_loop(data.String(), true, write_data)\n\tif err != nil {\n\t\tif err == tui.Canceled {","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/cmd/edit_in_kitty/main.go#L199-L235","documentation":"os.Getwd() failed while edit_in_kitty was building the environment payload (it embeds the current working directory for the editor session). Getwd fails when the CWD has been deleted or become unreadable — the kernel can no longer resolve '.' to a path.","triggerScenarios":"Running edit_in_kitty from a directory that was deleted (rm -rf by another process) or whose permissions no longer allow traversal, or from inside a mount point that vanished. Also possible when PWD env is stale and the fallback syscall fails with ENOENT/EACCES.","commonSituations":"Shell sitting in a removed temp/project dir (common after a build script cleans up), deleted container overlay dirs, or unmounted FUSE mounts that were the CWD.","solutions":["cd to a valid directory (e.g. cd ~ or cd /) before retrying","Recreate the deleted directory if the shell must stay there: mkdir -p <old-cwd>","Avoid launching editors from long-lived shells in temp dirs that get cleaned up","If a mount vanished, remount it or cd out of it"],"exampleFix":"# before (shell sits in a deleted dir)\nedit-in-kitty notes.txt   # getwd ENOENT\n# after\ncd ~ && edit-in-kitty /path/to/notes.txt","handlingStrategy":"fallback","validationCode":"// Verify CWD is resolvable before launching the editor\nif wd, err := os.Getwd(); err != nil {\n    fmt.Fprintln(os.Stderr, \"CWD lost; cd to a valid directory first\")\n    os.Chdir(os.Getenv(\"HOME\")) // recover into a known-good dir\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"Failed to get the current working directory\") {\n    os.Chdir(\"/\")\n    // retry with an absolute file path","preventionTips":["cd out of temp/project dirs before they're cleaned up","Pass absolute file paths so a lost CWD never corrupts the edit target","Scripts should os.Chdir to a stable dir before spawning editors"],"tags":["filesystem","cwd-deleted","getcwd","go"],"backgroundTag":"working-directory-lost","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}