{"record":{"id":"e0404786edd4cfb1","repo":"charmbracelet/crush","slug":"failed-to-delete-file-w","errorCode":null,"errorMessage":"failed to delete file: %w","messagePattern":"failed to delete file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/util/edit.go","lineNumber":204,"sourceCode":"\t\t}\n\t\tif err := os.WriteFile(path, []byte(\"\"), 0o644); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create file: %w\", err)\n\t\t}\n\t}\n\n\tif change.DeleteFile != nil {\n\t\tpath, err := change.DeleteFile.URI.Path()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid URI: %w\", err)\n\t\t}\n\n\t\tif change.DeleteFile.Options != nil && change.DeleteFile.Options.Recursive {\n\t\t\tif err := os.RemoveAll(path); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to delete directory recursively: %w\", err)\n\t\t\t}\n\t\t} else {\n\t\t\tif err := os.Remove(path); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to delete file: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\tif change.RenameFile != nil {\n\t\tvar newPath, oldPath string\n\t\tvar err error\n\n\t\toldPath, err = change.RenameFile.OldURI.Path()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tnewPath, err = change.RenameFile.NewURI.Path()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/lsp/util/edit.go#L186-L222","documentation":"For a non-recursive DeleteFile change, applyDocumentChange calls os.Remove on a single file (or empty directory); failure is wrapped with this message. Typical OS causes are ENOTEMPTY (directory not empty), ENOENT, or EACCES.","triggerScenarios":"os.Remove failing because the target is a non-empty directory without Recursive option, the file does not exist, or permissions deny removal of the parent directory.","commonSituations":"Deleting a folder without setting Options.Recursive; two tools racing to delete the same file; removing files from a directory the user cannot write to.","solutions":["Set Options.Recursive = true if the target is a non-empty directory.","Check existence first (os.Stat) if the file may already be gone.","Verify write+execute permission on the parent directory.","Inspect the wrapped OS error (ENOENT/ENOTEMPTY/EACCES) to pick the right fix."],"exampleFix":"// before\nchange.DeleteFile = &protocol.DeleteFile{URI: dirURI} // dir not empty\n// after\nchange.DeleteFile = &protocol.DeleteFile{URI: dirURI, Options: &protocol.DeleteFileOptions{Recursive: true}}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil {\n    return nil // already gone\n}\nif info.IsDir() && entries, _ := os.ReadDir(path); len(entries) > 0 {\n    recursive = true // must set DeleteFileOptions.Recursive\n}","typeGuard":null,"tryCatchPattern":"var rmErr *fs.PathError\nif errors.As(err, &rmErr) && errors.Is(rmErr.Err, syscall.ENOTEMPTY) {\n    // retry with Options.Recursive = true\n}","preventionTips":["Set Recursive for directories that may contain files.","Check existence before deleting to tolerate idempotent calls.","Ensure parent-directory write permission for unlink."],"tags":["lsp","file-io","delete"],"backgroundTag":"file-delete-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}