{"record":{"id":"0b347d1ff8ba9481","repo":"neoclide/coc.nvim","slug":"e-instanceof-error-e-message-string-e","errorCode":null,"errorMessage":"${e instanceof Error ? e.message : String(e)}","messagePattern":"\\$\\{e instanceof Error \\? e\\.message : String\\(e\\)\\}","errorType":"error_code","errorClass":"ResourceNotFoundError","httpStatus":null,"severity":"error","filePath":"src/mcp/resources.ts","lineNumber":82,"sourceCode":"        name: 'Document content',\n        description: 'Text content of an editor document (file URI encoded as parameter).'\n      }]\n    }\n  }\n\n  public async read(uri: string): Promise<{ contents: ResourceContent[] }> {\n    if (uri.startsWith(DOCUMENT_PREFIX)) {\n      let fileUri = decodeURIComponent(uri.slice(DOCUMENT_PREFIX.length))\n      let ref = await resolveDocument(fileUri, false)\n      if (ref.error) throw new ResourceNotFoundError(ref.error)\n      let text: string\n      if (ref.doc) {\n        text = ref.doc.getDocumentContent()\n      } else {\n        try {\n          text = fs.readFileSync(toFsPath(fileUri), 'utf8')\n        } catch (e) {\n          throw new ResourceNotFoundError(e instanceof Error ? e.message : String(e))\n        }\n      }\n      return { contents: [{ uri, mimeType: 'text/plain', text }] }\n    }\n    switch (uri) {\n      case 'coc://diagnostics': {\n        let list = await diagnosticManager.getDiagnosticList()\n        return { contents: [{ uri, mimeType: 'application/json', text: JSON.stringify(list, null, 2) }] }\n      }\n      case 'coc://services': {\n        let stats = services.getServiceStats().map(stat => {\n          let service = services.getService(stat.id)\n          let init = service?.client?.initializeResult\n          return {\n            id: stat.id,\n            state: stat.state,\n            languageIds: stat.languageIds,\n            capabilities: init?.capabilities ?? null","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/mcp/resources.ts#L64-L100","documentation":"For a `coc://document/<uri>` resource backed by a real file (not an open document), the server reads the file from disk with `fs.readFileSync`. Any filesystem failure (ENOENT, EACCES, EISDIR) is wrapped into a `ResourceNotFoundError` with the underlying error message.","triggerScenarios":"`resources.read('coc://document/<file-uri>')` where the file does not exist, lacks read permission, or the URI points to a directory — the readFileSync throws and the message (e.g. 'ENOENT: no such file or directory') becomes the error text.","commonSituations":"File deleted or moved after being listed as a resource; wrong absolute path in the URI; permission issues when the server runs as a different user; passing a directory instead of a file.","solutions":["Check the exact message (ENOENT vs EACCES vs EISDIR) to identify the filesystem problem","Verify the file exists and is readable at the encoded path","Re-list resources to refresh URIs after files moved","Do not wrap the encoded URI again (double-encoding produces a wrong path)"],"exampleFix":"// before\nawait read('coc://document/' + encodeURIComponent('file:///missing.txt')) // double-encoded\n// after\nawait read(URI.file('/missing.txt').toString().replace('file://', 'coc://document/'))","handlingStrategy":"try-catch","validationCode":"const fileUri = decodeURIComponent(uri.slice('coc://document/'.length))\nconst stat = fs.existsSync(toFsPath(fileUri)) ? fs.statSync(toFsPath(fileUri)) : null\nif (!stat) throw new Error(`File not found: ${fileUri}`)\nif (!stat.isFile()) throw new Error(`Not a regular file: ${fileUri}`)","typeGuard":null,"tryCatchPattern":"try {\n  const res = await resources.read(uri)\n} catch (e) {\n  if (/ENOENT/.test(e.message)) logger.warn(`File gone: ${uri}`)\n  else if (/EACCES/.test(e.message)) logger.error(`Permission denied: ${uri}`)\n  else if (/EISDIR/.test(e.message)) logger.error(`URI points to a directory: ${uri}`)\n  else throw e\n}","preventionTips":["Check file existence before embedding paths in document resource URIs","Avoid pointing resources at directories","Re-check filesystem state after long-running sessions","Distinguish ENOENT/EACCES/EISDIR in handlers"],"tags":["mcp","filesystem","resource-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}