From cde84508acd604caaf45087cfd3dab6dbecf1cc1 Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Thu, 20 Aug 2026 02:10:48 -0400 Subject: [PATCH] fix(generate)!: error when nonexistent _file_ path is passed to `generate_parser_in_directory`. --- crates/generate/src/generate.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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;