{"record":{"id":"487c790e9ba0de76","repo":"neoclide/coc.nvim","slug":"folder-should-be-string","errorCode":null,"errorMessage":"folder should be string","messagePattern":"folder should be string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/handler/workspace.ts","lineNumber":180,"sourceCode":"    }\n    await workspace.jumpTo(URI.file(path.join(dir, CONFIG_FILE_NAME)))\n  }\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}`,","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/handler/workspace.ts#L162-L198","documentation":"coc.nvim's addWorkspaceFolder API only accepts a string path; it throws a TypeError immediately when the argument is not a string. This is an eager argument validation so bad input fails fast before any filesystem or workspace-folder state is touched.","triggerScenarios":"Calling workspace.addWorkspaceFolder with a non-string value, e.g. null/undefined, a URI object, or a number.","commonSituations":"Passing a workspaceFolder object instead of its name/uri string; passing an optional config value that is undefined; callers that resolved a folder from an async API and forgot `await`.","solutions":["Convert the argument to a string before calling (e.g. folder.uri or String(folder)).","If the value may be undefined, check it and bail out or use a default before calling.","Ensure the path exists as a directory too, or the next error (directory not exists) will fire."],"exampleFix":"// before\nworkspace.addWorkspaceFolder(folder?.uri)\n// after\nif (folder && typeof folder.uri === 'string') workspace.addWorkspaceFolder(folder.uri)","handlingStrategy":"type-guard","validationCode":"if (typeof folder !== 'string' || folder.length === 0) throw new Error('addWorkspaceFolder needs a non-empty string path')","typeGuard":"function isFolderString(v: unknown): v is string { return typeof v === 'string' }","tryCatchPattern":"try { workspace.addWorkspaceFolder(folder) } catch (e) { if (String(e).includes('folder should be string')) { /* fix input type */ } else throw e }","preventionTips":["Always derive the path string from WorkspaceFolder.name or .uri.toString()","Type the parameter as string in wrapper functions so TS catches wrong types","Check optional config values for undefined before use"],"tags":["type-error","argument-validation","workspace"],"backgroundTag":"invalid-argument-type","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}