{"record":{"id":"02421eaaf918c795","repo":"BoundaryML/baml","slug":"baml-generate-failed-project-has-errors","errorCode":null,"errorMessage":"BAML Generate failed - Project has errors.","messagePattern":"BAML Generate failed - Project has errors\\.","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/language_server/src/baml_project/mod.rs","lineNumber":1225,"sourceCode":"    //                 file_map.insert(parts[0].to_string(), parts[1].to_string());\n    //             }\n    //         }\n    //         // let diagnostics = self.baml_project.diagnostics(runtime);\n    //         // (self.on_success)(diagnostics, file_map);\n    //         todo!()\n    //     }\n    //     Ok(())\n    // }\n    //\n\n    /// Retrieves a reference to the current runtime or the last successful one.\n    pub fn runtime(&self) -> anyhow::Result<&BamlRuntime> {\n        if let Some(ref rt) = self.current_runtime {\n            Ok(rt)\n        } else if let Some(ref rt) = self.last_successful_runtime {\n            Ok(rt)\n        } else {\n            Err(anyhow::anyhow!(\n                \"BAML Generate failed - Project has errors.\"\n            ))\n        }\n    }\n\n    /// Returns a map of file URIs to their content.\n    pub fn files(&self) -> HashMap<String, String> {\n        let files = self.baml_project.files();\n        let mut file_map = HashMap::new();\n        for file in files {\n            let parts: Vec<&str> = file.splitn(2, \"BAML_PATH_SPLTTER\").collect();\n            if parts.len() == 2 {\n                file_map.insert(parts[0].to_string(), parts[1].to_string());\n            }\n        }\n        file_map\n    }\n","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_server/src/baml_project/mod.rs#L1207-L1243","documentation":"BamlProject.runtime() throws \"BAML Generate failed - Project has errors.\" when neither current_runtime nor last_successful_runtime is available — i.e. the project's BAML has never compiled successfully in this session. Callers (hover, list_functions, list_expr_fns, test-pair listing, generator-version handlers) all depend on a valid runtime, so they fail with this message until the BAML source compiles.","triggerScenarios":"Any query hitting the language server (hover, function listing, expression-function listing, function/test-pair listing, get/send_generator_version) while the project contains only a broken runtime: BAML files have compile errors from the start, or the project was opened before any successful generate.","commonSituations":"Opening an editor on a project with a freshly introduced .baml syntax error; a brand-new project where baml-cli generate was never run successfully; dependency/config (e.g. baml_version or client config) errors preventing the first successful build.","solutions":["Fix the BAML compile errors reported in the editor diagnostics / codegen output so runtime() can build a runtime","Run baml-cli generate (or save a .baml file to trigger the LSP rebuild) to produce a successful runtime","Verify baml_src configuration and BAML schema version in generators.baml are valid","Restart the language server after fixing errors to clear the failed state"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Guard callers before querying:\nif baml_project.runtime().is_err() {\n    eprintln!(\"BAML project has no successful runtime yet; fix compile errors and regenerate.\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"match baml_project.runtime() {\n    Ok(rt) => use_runtime(rt),\n    Err(e) if e.to_string().contains(\"Project has errors.\") => {\n        eprintln!(\"Project never compiled: fix BAML errors and run baml-cli generate.\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Fix editor diagnostics in .baml files before invoking language-server queries that need the runtime","Run baml-cli generate in CI to catch broken BAML before any consumer starts","Save/trigger a rebuild after every error fix so a successful runtime is cached","Validate generators.baml and client configs when bootstrapping a new project"],"tags":["rust","language-server","baml","runtime","project-errors"],"backgroundTag":"schema-validation-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}