BoundaryML/baml · error

InternalError

InternalError

Error message

File {} was not present in the project

What it means

This InternalError is raised by the BAML language server's rename request handler when the document key sent by the client is not found in the project's file map. The server cannot compute a rename because it has no tracked file matching the client's document, usually meaning the server and client state are out of sync.

Source

Thrown at engine/language_server/src/server/api/requests/rename.rs:52

        let url = params.text_document_position.text_document.uri;
        let path = url
            .to_file_path()
            .internal_error_msg("Could not convert URL to path")?;
        let Ok(project) = session.get_or_create_project(&path) else {
            return Ok(None);
        };

        let res = {
            let mut guard = project.lock();
            let document_key =
                DocumentKey::from_url(&PathBuf::from(guard.root_path()), &url).internal_error()?;

            // Get the symbol under point.
            let doc = guard
                .baml_project
                .files
                .get(&document_key)
                .ok_or(anyhow::anyhow!(
                    "File {} was not present in the project",
                    document_key
                ))
                .internal_error()?;
            let symbol =
                get_word_at_position(&doc.contents, &params.text_document_position.position);
            let new_symbol = params.new_name;

            // If the symbol is a class, find all occurrences and replace them.
            let default_flags = vec!["beta".to_string()];
            let runtime = guard.baml_project.runtime(
                HashMap::new(),
                session
                    .baml_settings
                    .feature_flags
                    .as_ref()
                    .unwrap_or(&default_flags),
            );

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure the file is opened/indexed in the project (didOpen or project load) before issuing a rename request.
  2. Verify the document URI passed to rename exactly matches the key format the server stores in baml_project.files.
  3. Check that the project loader/file watcher picked up the file (reload the window or restart the language server).
  4. Return a proper RequestFailed/invalid-params error to the client instead of InternalError when the document is absent.

Example fix

// before
let doc = guard.baml_project.files.get(&document_key).ok_or(anyhow::anyhow!("File {} was not present in the project", document_key)).internal_error()?;
// after
let Some(doc) = guard.baml_project.files.get(&document_key) else {
    return Err(jsonrpc::Error::invalid_params(format!("File {} is not open in the project", document_key)));
};
Defensive patterns

Strategy: validation

When it happens

Trigger: Calling the LSP textDocument/rename request with a document URI that was never opened via didOpen, was closed via didClose, or whose key does not match any file registered in baml_project.files.

Common situations: Clients racing a rename with file close, stale editor buffers pointing at deleted/moved .baml files, tests invoking the rename handler with a fabricated document key, or the project file watcher not having indexed the file yet.

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/4ea1b78df2ff1fac. Report an issue: GitHub.