{"record":{"id":"917df0c56083ae5c","repo":"BoundaryML/baml","slug":"dir-is-a-file-not-a-directory-expected-a-directory","errorCode":null,"errorMessage":"{dir:#?} is a file, not a directory (expected a directory containing BAML files)","messagePattern":"(.+?) is a file, not a directory \\(expected a directory containing BAML files\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/lib.rs","lineNumber":2247,"sourceCode":"        &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}\");\n                None\n            }\n        })","sourceCodeStart":2229,"sourceCodeEnd":2265,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/lib.rs#L2229-L2265","documentation":"baml_src_files() expects the given path to be a directory containing .baml files. After confirming the path exists, it checks that the path is not a regular file; pointing it at a file raises this error. It guards against passing something like a single .baml file or a config file where a directory is expected.","triggerScenarios":"Calling baml_src_files with a PathBuf such as \"baml_src/main.baml\" or any other file path instead of the directory (e.g. \"./baml_src\").","commonSituations":"Configuring the editor extension or runtime with the path to a single .baml file instead of the source folder; accidentally passing a config file (baml.json) as the source path; shell scripts that append a filename to the source directory.","solutions":["Pass the directory (e.g. ./baml_src), not a file inside it","Remove any trailing filename from the configured baml_src path in your CLI args or runtime config","Point editor extension settings at the baml_src folder, not an individual .baml file"],"exampleFix":"// before\nbaml_src_files(&PathBuf::from(\"baml_src/main.baml\"))?\n\n// after\nbaml_src_files(&PathBuf::from(\"baml_src\"))?","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nconst p = './baml_src';\nif (fs.existsSync(p) && !fs.statSync(p).isDirectory()) throw new Error(`${p} must be the baml_src directory, not a file`);","typeGuard":"function isDirectory(p: string): boolean {\n  try { return fs.statSync(p).isDirectory(); } catch { return false; }\n}","tryCatchPattern":"try {\n  bamlSrcFiles(dir);\n} catch (e) {\n  if (/is a file, not a directory/i.test(e.message)) {\n    console.error(`Pass the folder (e.g. ./baml_src) instead of a file: ${dir}`);\n  }\n  throw e;\n}","preventionTips":["Point configs and editor settings at the baml_src folder, never an individual .baml file","Strip trailing filenames from path variables before calling generation APIs","Keep a single source of truth for the baml_src path in your build scripts"],"tags":["filesystem","path","baml","directory"],"backgroundTag":"path-is-not-a-directory","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"}