{"record":{"id":"e23f06054ed8f82c","repo":"BoundaryML/baml","slug":"dir-is-not-a-directory-expected-a-directory-containing-baml","errorCode":null,"errorMessage":"{dir:#?} is not a directory (expected a directory containing BAML files)","messagePattern":"(.+?) is 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":2252,"sourceCode":"    }\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        })\n        .filter(|e| e.file_type().is_file())\n        .filter(|e| {\n            let Some(ext) = e.path().extension() else {\n                return false;\n            };","sourceCodeStart":2234,"sourceCodeEnd":2270,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/lib.rs#L2234-L2270","documentation":"As a final shape check, baml_src_files() requires the path to actually be a directory (dir.is_dir()). This branch handles exotic cases where a path exists, is not a file, but is also not a directory — e.g. special files, sockets, FIFOs, or device nodes. It ensures the walker below only ever runs against a real directory.","triggerScenarios":"Calling baml_src_files with a path that exists but is neither a file nor a directory: a Unix socket, FIFO, symlink to a special file, or device node at the baml_src location.","commonSituations":"Rare in practice: a broken symlink resolution creating a special file where baml_src/ should be; a bind-mount or container volume mapping a socket/device to that path; corrupted build outputs.","solutions":["Remove the special file at that path and restore a real baml_src directory (`mkdir baml_src` and restore your .baml files)","Check where the path points with `ls -la` / `stat baml_src` and fix the symlink or mount","Correct the configured baml_src path if it points at a runtime artifact (socket/pipe) instead of the source folder"],"exampleFix":"// before (path is a socket/fifo)\n$ stat baml_src  # Type: socket\n\n// after\n$ rm baml_src\n$ mkdir baml_src && mv *.baml baml_src/","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nconst st = fs.lstatSync(dir);\nif (!st.isDirectory()) throw new Error(`${dir} exists but is not a regular directory (${st.mode}); fix symlinks/mounts`);","typeGuard":null,"tryCatchPattern":"try {\n  bamlSrcFiles(dir);\n} catch (e) {\n  if (/is not a directory/i.test(e.message)) {\n    console.error(`${dir} is a special file/socket/broken symlink; restore a real directory there`);\n  }\n  throw e;\n}","preventionTips":["Use ls -la / stat to inspect the baml_src path if it behaves oddly","Avoid bind-mounting sockets or devices into your source tree","Restore directories after failed container volume mounts"],"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"}