diff --git a/crates/generate/src/generate.rs b/crates/generate/src/generate.rs index 0cccefe8f..61d5e3f51 100644 --- a/crates/generate/src/generate.rs +++ b/crates/generate/src/generate.rs @@ -82,6 +82,8 @@ pub enum GenerateError { #[cfg(feature = "load")] #[error(transparent)] LoadGrammarFile(#[from] LoadGrammarError), + #[error("Grammar file `{0}` not found")] + GrammarFileNotFound(PathBuf), #[error(transparent)] ParseGrammar(#[from] ParseGrammarError), #[error(transparent)] @@ -347,6 +349,11 @@ where .try_exists() .map_err(|e| GenerateError::GrammarPath(e.to_string()))? { + // A nonexistent path with an extension (i.e. tree-sitter-foo/grammar.json) + // is a missing input file, not a directory to create. + if path_buf.extension().is_some() { + return Err(GenerateError::GrammarFileNotFound(path_buf)); + } fs::create_dir_all(&path_buf) .map_err(|e| GenerateError::IO(IoError::new(e, Some(path_buf.as_path()))))?; repo_path = path_buf;