BoundaryML/baml · error
is not a directory (expected a directory containing BAML…
Error message
{dir:#?} is not a directory (expected a directory containing BAML files) What it means
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.
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
Example fix
// before (path is a socket/fifo) $ stat baml_src # Type: socket // after $ rm baml_src $ mkdir baml_src && mv *.baml baml_src/
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
const st = fs.lstatSync(dir);
if (!st.isDirectory()) throw new Error(`${dir} exists but is not a regular directory (${st.mode}); fix symlinks/mounts`); Try / catch
try {
bamlSrcFiles(dir);
} catch (e) {
if (/is not a directory/i.test(e.message)) {
console.error(`${dir} is a special file/socket/broken symlink; restore a real directory there`);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- does not exist (expected a directory containing BAML files)
- is a file, not a directory (expected a directory containing…
- Expected --from ' ' to be a baml_src/ directory, but it…
- Expected --from ' ' to be a baml_src/ directory, but it is…
- Failed to gather files from directory
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/e23f06054ed8f82c.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-runtime/src/lib.rs:2252
}
}
#[cfg(not(target_arch = "wasm32"))]
pub fn baml_src_files(dir: &std::path::PathBuf) -> Result<Vec<PathBuf>> {
static VALID_EXTENSIONS: [&str; 1] = ["baml"];
log::trace!("Reading files from {:#}", dir.to_string_lossy());
if !dir.exists() {
anyhow::bail!("{dir:#?} does not exist (expected a directory containing BAML files)",);
}
if dir.is_file() {
return Err(anyhow::anyhow!(
"{dir:#?} is a file, not a directory (expected a directory containing BAML files)",
));
}
if !dir.is_dir() {
return Err(anyhow::anyhow!(
"{dir:#?} is not a directory (expected a directory containing BAML files)",
));
}
let src_files = walkdir::WalkDir::new(dir)
.into_iter()
.filter_map(|e| match e {
Ok(e) => Some(e),
Err(e) => {
log::error!("Error while reading files from {dir:#?}: {e}");
None
}
})
.filter(|e| e.file_type().is_file())
.filter(|e| {
let Some(ext) = e.path().extension() else {
return false;
};View on GitHub (pinned to bd85ce9dee)