{"record":{"id":"b42a1b210ee984ad","repo":"neoclide/coc.nvim","slug":"ref-error","errorCode":null,"errorMessage":"${ref.error}","messagePattern":"\\$\\{ref\\.error\\}","errorType":"error_code","errorClass":"ResourceNotFoundError","httpStatus":null,"severity":"error","filePath":"src/mcp/resources.ts","lineNumber":74,"sourceCode":"    resources.push({ uri: 'coc://workspace', name: 'Workspace information', mimeType: 'application/json' })\n    return { resources }\n  }\n\n  public listTemplates(): { resourceTemplates: ResourceTemplateInfo[] } {\n    return {\n      resourceTemplates: [{\n        uriTemplate: DOCUMENT_PREFIX + '{uri}',\n        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': {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/mcp/resources.ts#L56-L92","documentation":"Reading an MCP `coc://document/<uri>` resource resolves the URI to a document reference via `resolveDocument`. When resolution returns an `error` (e.g. the URI is malformed or the document cannot be attached), the server converts it into a `ResourceNotFoundError` carrying the resolver's message.","triggerScenarios":"Calling `resources.read('coc://document/<bad-uri>')` where the embedded file URI fails resolution — unresolvable scheme, non-existent/unopenable file, or an invalid encoded URI after `decodeURIComponent`.","commonSituations":"An MCP client constructed a document resource URI by hand and percent-encoded it incorrectly; the file was deleted between listing and reading; the path is outside the workspace and cannot be resolved to a document.","solutions":["Verify the document URI is a valid, correctly percent-encoded file:// URI","Confirm the file exists and is readable at the path encoded in the URI","Re-list resources (`resources/list`) to get fresh, valid URIs instead of reusing cached ones"],"exampleFix":"// before\nawait resources.read('coc://document/' + '/my file.txt')\n// after\nawait resources.read('coc://document/' + encodeURIComponent(URI.file('/my file.txt').toString()))","handlingStrategy":"validation","validationCode":"function toDocumentResourceUri(fsPath: string): string {\n  return 'coc://document/' + encodeURIComponent(URI.file(fsPath).toString())\n}\nconst uri = toDocumentResourceUri('/path/to/file.ts')\nif (!fs.existsSync(URI.parse(decodeURIComponent(uri.slice('coc://document/'.length))).fsPath)) {\n  throw new Error('File missing before resource read')\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await resources.read(uri)\n} catch (e) {\n  if (e instanceof ResourceNotFoundError) {\n    logger.warn(`Resource unavailable: ${uri}: ${e.message}`)\n  } else throw e\n}","preventionTips":["Build document resource URIs with proper encoding helpers, never string concatenation of raw paths","Re-list resources after files move or are deleted","Check the resolver error message to distinguish encoding vs existence problems"],"tags":["mcp","resource-not-found","uri"],"backgroundTag":"resource-not-found","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}