sinelaw/fresh · error · io::Error
InvalidInput
InvalidInput
Error message
Path is not a directory: {:?} What it means
After confirming the root exists, `FileTree::new` checks that it is a directory; a plain file (or other non-directory) yields `io::ErrorKind::InvalidInput` with "Path is not a directory". The tree can only be rooted at directories.
Solutions
- Pass a directory path as the root, not a file
- Validate `is_dir` before constructing and route file paths to a file-open flow instead
- If a file was selected, root the tree at its parent directory
Example fix
// before
let tree = FileTree::new(path, fs.clone()).await?;
// after
let root = if fs.is_dir(&path).await? { path } else { path.parent().unwrap().to_path_buf() };
let tree = FileTree::new(root, fs.clone()).await?; Defensive patterns
Strategy: validation
Validate before calling
if std::path::Path::new(&root_path).is_file() {
let root_path = root_path.parent().unwrap().to_path_buf();
} Try / catch
match FileTree::new(root_path, fs).await {
Err(e) if e.kind() == io::ErrorKind::InvalidInput => eprintln!("{} is not a directory", root_path.display()),
other => other?,
} Prevention
- Only pass directories from file pickers (set the dialog to select directories)
- Route file selections to the editor's open-file flow
- Check is_dir before building trees
- Normalize and validate configured workspace paths
When it happens
Trigger: Calling `FileTree::new` with a path that exists but `fs_manager.is_dir()` reports false — most commonly passing a file path as the tree root.
Common situations: Users selecting a file instead of a folder in an open dialog; config pointing at a single file; scripts passing a filename where a directory is expected.
Related errors
AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13).
Data as JSON: /api/errors/3eece7d7b78bb68d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/fresh-editor/src/view/file_tree/tree.rs:46
}
impl FileTree {
/// Create a new file tree rooted at the given path
///
/// # Errors
///
/// Returns an error if the root path doesn't exist or isn't a directory.
pub async fn new(root_path: PathBuf, fs_manager: Arc<FsManager>) -> io::Result<Self> {
// Verify root path exists and is a directory
if !fs_manager.exists(&root_path).await {
return Err(io::Error::new(
io::ErrorKind::NotFound,
format!("Path does not exist: {:?}", root_path),
));
}
if !fs_manager.is_dir(&root_path).await? {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Path is not a directory: {:?}", root_path),
));
}
// Get root entry
let root_entry = fs_manager.get_entry(&root_path).await?;
// Create root node
let root_id = NodeId(0);
let root_node = TreeNode::new(root_id, root_entry.clone(), None);
let mut nodes = HashMap::new();
nodes.insert(root_id, root_node);
let mut path_to_node = HashMap::new();
path_to_node.insert(root_path.clone(), root_id);
View on GitHub (pinned to 67894ca546)