fix(generate)!: error when nonexistent _file_ path is passed to

`generate_parser_in_directory`.
This commit is contained in:
Will Lillis 2026-08-20 02:10:48 -04:00
parent 43623ec9bf
commit cde84508ac

View file

@ -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;