{"record":{"id":"ce88355ea841bac9","repo":"BoundaryML/baml","slug":"dir-does-not-exist-expected-a-directory-containing-baml","errorCode":null,"errorMessage":"{dir:#?} does not exist (expected a directory containing BAML files)","messagePattern":"(.+?) does not exist \\(expected a directory containing BAML files\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/lib.rs","lineNumber":2244,"sourceCode":"    }\n\n    fn get_test_type_builder(\n        &self,\n        function_name: &str,\n        test_name: &str,\n    ) -> Result<Option<TypeBuilder>> {\n        self.get_test_type_builder_impl(function_name, test_name)\n    }\n}\n\n#[cfg(not(target_arch = \"wasm32\"))]\npub fn baml_src_files(dir: &std::path::PathBuf) -> Result<Vec<PathBuf>> {\n    static VALID_EXTENSIONS: [&str; 1] = [\"baml\"];\n\n    log::trace!(\"Reading files from {:#}\", dir.to_string_lossy());\n\n    if !dir.exists() {\n        anyhow::bail!(\"{dir:#?} does not exist (expected a directory containing BAML files)\",);\n    }\n    if dir.is_file() {\n        return Err(anyhow::anyhow!(\n            \"{dir:#?} is a file, not a directory (expected a directory containing BAML files)\",\n        ));\n    }\n    if !dir.is_dir() {\n        return Err(anyhow::anyhow!(\n            \"{dir:#?} is not a directory (expected a directory containing BAML files)\",\n        ));\n    }\n\n    let src_files = walkdir::WalkDir::new(dir)\n        .into_iter()\n        .filter_map(|e| match e {\n            Ok(e) => Some(e),\n            Err(e) => {\n                log::error!(\"Error while reading files from {dir:#?}: {e}\");","sourceCodeStart":2226,"sourceCodeEnd":2262,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/lib.rs#L2226-L2262","documentation":"baml_src_files() validates the directory it's asked to scan for .baml files before walking it. The very first check confirms the path exists at all; if it doesn't, the function bails with this error embedding the debug-formatted path. This is typically the first failure users see when the baml_src path is misconfigured.","triggerScenarios":"Calling baml_src_files (via project loading / baml-cli commands / LoadSrcArgs with baml_src path) with a PathBuf that does not exist on disk.","commonSituations":"Running the CLI from the wrong working directory so the relative baml_src/ path doesn't resolve; deleting or renaming the baml_src folder; misconfigured project root in an editor plugin or a packaged app where the sources weren't bundled.","solutions":["Run the command from the project root so the relative baml_src path resolves (or pass an absolute path)","Verify the directory exists with `ls baml_src` and create/rename it if it was moved or deleted","Fix the configured baml_src path in your tooling (baml-cli args, editor extension settings, or runtime LoadSrcArgs)","If bundling an app, ensure the baml_src directory is included in the artifact next to the binary"],"exampleFix":"// before\nlet files = baml_src_files(&PathBuf::from(\"./baml_sorc\"))?; // typo\n\n// after\nlet files = baml_src_files(&PathBuf::from(\"./baml_src\"))?;","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nconst dir = './baml_src';\nif (!fs.existsSync(dir)) throw new Error(`${dir} does not exist; run from the project root or fix the baml_src path`);","typeGuard":null,"tryCatchPattern":"try {\n  const files = bamlSrcFiles(dir);\n} catch (e) {\n  if (/does not exist/i.test(e.message)) {\n    console.error(`Directory not found: ${e.message}. Check cwd and the baml_src path configuration.`);\n  }\n  throw e;\n}","preventionTips":["Always run baml-cli from the project root, or pass absolute paths","Commit the baml_src directory and don't move it without updating configs","In packaged apps, ensure baml_src is bundled next to the binary","Verify the path with ls before invoking generation tooling"],"tags":["filesystem","path","baml","directory"],"backgroundTag":"directory-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}