BoundaryML/baml · error

tried to close document that didn't exist at

Error message

tried to close document that didn't exist at {}

What it means

Raised by Index::close_document when a textDocument/didClose arrives for a document key that is not present in the index. The server treats closing an unknown document as an error rather than silently ignoring it.

Solutions

  1. Only send textDocument/didClose for URIs previously confirmed opened via didOpen
  2. Handle/deduplicate close notifications on the client side
  3. If this appears after a server crash/restart, reopen the document (didOpen) before closing
  4. Log and ignore benign duplicate closes in the client integration

Example fix

// before
client.close(uri);
client.close(uri); // duplicate
// after
if (openDocs.has(uri)) { client.close(uri); openDocs.delete(uri); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (!openDocuments.has(uri)) return; // skip close for unknown docs

Type guard

function isOpen(uri: string): boolean { return openDocuments.has(uri); }

Try / catch

try { await sendDidClose(uri); } catch (e) { if (String(e).includes("didn't exist")) { openDocuments.delete(uri); } else throw e; }

Prevention

When it happens

Trigger: didClose for a URI that was never didOpen'd; duplicate didClose notifications; didClose after a server restart that cleared the index.

Common situations: Editor plugins firing didClose on virtual/untitled buffers never opened; race where client thinks a doc is open after server reload; double-close from client retry logic.

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 BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/0a528f26daef68e6. Report an issue: GitHub.

Appendix: source

Thrown at engine/language_server/src/session/index.rs:83

    pub fn make_document_ref(&self, document_key: DocumentKey) -> Option<DocumentQuery> {
        // let url = self.url_for_key(&key)?.clone();
        let controller = self.documents.get(&document_key)?;
        Some(controller.make_ref(document_key))
    }

    pub fn open_text_document(&mut self, document_key: DocumentKey, document: TextDocument) {
        self.documents
            .insert(document_key, DocumentController::new_text(document));
    }

    pub fn close_document(&mut self, document_key: &DocumentKey) -> anyhow::Result<()> {
        // let Some(url) = self.url_for_key(key).cloned() else {
        //     anyhow::bail!("Tried to close unavailable document `{key}`");
        // };

        let Some(_) = self.documents.remove(document_key) else {
            anyhow::bail!(
                "tried to close document that didn't exist at {}",
                document_key
            )
        };
        Ok(())
    }

    pub fn document_controller_for_key(
        &mut self,
        document_key: &DocumentKey,
    ) -> anyhow::Result<&mut DocumentController> {
        let Some(controller) = self.documents.get_mut(document_key) else {
            anyhow::bail!("Document controller not available at `{}`", document_key);
        };
        Ok(controller)
    }

    // fn url_for_key<'a>(&'a self, key: &'a DocumentKey) -> Option<&'a Url> {

View on GitHub (pinned to bd85ce9dee)