{"record":{"id":"765623c453670a90","repo":"neoclide/coc.nvim","slug":"directory-folder-not-exists","errorCode":null,"errorMessage":"Directory ${folder} not exists","messagePattern":"Directory (.+?) not exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/handler/workspace.ts","lineNumber":182,"sourceCode":"  }\n\n  public async renameCurrent(): Promise<void> {\n    let { nvim } = this\n    let oldPath = await nvim.call('coc#util#get_fullpath', []) as string\n    let newPath = await callAsync(nvim, 'input', ['New path: ', oldPath, 'file']) as string\n    newPath = newPath.trim()\n    if (newPath === oldPath || !newPath) return\n    if (oldPath.toLowerCase() != newPath.toLowerCase() && fs.existsSync(newPath)) {\n      let overwrite = await window.showPrompt(`${newPath} exists, overwrite?`)\n      if (!overwrite) return\n    }\n    await workspace.renameFile(oldPath, newPath, { overwrite: true })\n  }\n\n  public addWorkspaceFolder(folder: string): void {\n    if (!Is.string(folder)) throw TypeError(`folder should be string`)\n    folder = workspace.expand(folder)\n    if (!isDirectory(folder)) throw directoryNotExists(folder)\n    workspace.workspaceFolderControl.addWorkspaceFolder(folder, true)\n  }\n\n  public removeWorkspaceFolder(folder: string): void {\n    if (!Is.string(folder)) throw TypeError(`folder should be string`)\n    folder = workspace.expand(folder)\n    if (!isDirectory(folder)) throw directoryNotExists(folder)\n    workspace.workspaceFolderControl.removeWorkspaceFolder(folder)\n  }\n\n  public async bufferCheck(): Promise<void> {\n    let doc = await workspace.document\n    if (!doc.attached) {\n      await window.showDialog({\n        title: 'Buffer check result',\n        content: `Document not attached, ${doc.notAttachReason}`,\n        highlight: 'WarningMsg'\n      })","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/handler/workspace.ts#L164-L200","documentation":"After string validation, addWorkspaceFolder expands the path (supporting ~ and variables) and checks that it is an existing directory via isDirectory; a nonexistent path or a file path throws directoryNotExists with the message \"Directory <folder> not exists\".","triggerScenarios":"Calling workspace.addWorkspaceFolder with a path that does not exist on disk, points to a file instead of a directory, or contains an unexpanded variable that expands to nothing.","commonSituations":"Typo in the configured workspace folder path; path valid on a remote/WSL host but not locally; passing a file path instead of the containing directory; stale config after the folder was deleted or renamed.","solutions":["Verify the path with fs.existsSync/isDirectory before calling and correct typos.","Pass the directory, not a file, when adding a workspace root.","Expand user home/variables yourself (or confirm coc's expand handles them) so the resolved path exists.","Remove or update stale workspace-folder config entries pointing to deleted folders."],"exampleFix":"// before\nworkspace.addWorkspaceFolder('~/projcts/app')\n// after\nconst p = require('path').join(require('os').homedir(), 'projects', 'app')\nif (require('fs').statSync(p).isDirectory()) workspace.addWorkspaceFolder(p)","handlingStrategy":"validation","validationCode":"const st = fs.statSync(folder, { throwIfNoEntry: false })\nif (!st || !st.isDirectory()) throw new Error(`Directory does not exist: ${folder}`)","typeGuard":null,"tryCatchPattern":"try { workspace.addWorkspaceFolder(folder) } catch (e) { if (String(e).includes('not exists')) { /* prompt user for a valid directory */ } else throw e }","preventionTips":["statSync().isDirectory() every user-supplied path before adding","Use fs.realpathSync to normalize symlinks and casing","Validate config paths at startup and warn early"],"tags":["filesystem","validation","workspace"],"backgroundTag":"directory-not-found","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}