neoclide/coc.nvim · error · ResourceNotFoundError

${ref.error}

Error message

${ref.error}

What it means

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.

Source

Thrown at src/mcp/resources.ts:74

    resources.push({ uri: 'coc://workspace', name: 'Workspace information', mimeType: 'application/json' })
    return { resources }
  }

  public listTemplates(): { resourceTemplates: ResourceTemplateInfo[] } {
    return {
      resourceTemplates: [{
        uriTemplate: DOCUMENT_PREFIX + '{uri}',
        name: 'Document content',
        description: 'Text content of an editor document (file URI encoded as parameter).'
      }]
    }
  }

  public async read(uri: string): Promise<{ contents: ResourceContent[] }> {
    if (uri.startsWith(DOCUMENT_PREFIX)) {
      let fileUri = decodeURIComponent(uri.slice(DOCUMENT_PREFIX.length))
      let ref = await resolveDocument(fileUri, false)
      if (ref.error) throw new ResourceNotFoundError(ref.error)
      let text: string
      if (ref.doc) {
        text = ref.doc.getDocumentContent()
      } else {
        try {
          text = fs.readFileSync(toFsPath(fileUri), 'utf8')
        } catch (e) {
          throw new ResourceNotFoundError(e instanceof Error ? e.message : String(e))
        }
      }
      return { contents: [{ uri, mimeType: 'text/plain', text }] }
    }
    switch (uri) {
      case 'coc://diagnostics': {
        let list = await diagnosticManager.getDiagnosticList()
        return { contents: [{ uri, mimeType: 'application/json', text: JSON.stringify(list, null, 2) }] }
      }
      case 'coc://services': {

View on GitHub (pinned to 50e974d969)

Solutions

  1. Verify the document URI is a valid, correctly percent-encoded file:// URI
  2. Confirm the file exists and is readable at the path encoded in the URI
  3. Re-list resources (`resources/list`) to get fresh, valid URIs instead of reusing cached ones

Example fix

// before
await resources.read('coc://document/' + '/my file.txt')
// after
await resources.read('coc://document/' + encodeURIComponent(URI.file('/my file.txt').toString()))
Defensive patterns

Strategy: validation

Validate before calling

function toDocumentResourceUri(fsPath: string): string {
  return 'coc://document/' + encodeURIComponent(URI.file(fsPath).toString())
}
const uri = toDocumentResourceUri('/path/to/file.ts')
if (!fs.existsSync(URI.parse(decodeURIComponent(uri.slice('coc://document/'.length))).fsPath)) {
  throw new Error('File missing before resource read')
}

Try / catch

try {
  const res = await resources.read(uri)
} catch (e) {
  if (e instanceof ResourceNotFoundError) {
    logger.warn(`Resource unavailable: ${uri}: ${e.message}`)
  } else throw e
}

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31). Data as JSON: /api/errors/b42a1b210ee984ad. Report an issue: GitHub.