fix(cli): improve error message when language in list can't be found (#4643)

Problem: When multiple input paths are provided to the `parse` command (a la `tree-sitter parse --paths [...]`), if a language can't be found for one of the paths, it can be a little unclear *which* path caused the failure. The loader *can* fail with `Failed to load language for file name <foo.bar>`, but this isn't guaranteed. 

Solution: Attach some additional context in the case where multiple paths can be provided, displaying the problematic path on failure.
This commit is contained in:
Will Lillis 2025-08-02 05:52:54 -04:00 committed by GitHub
parent 07b4c8d05d
commit 9ced6172de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1023,8 +1023,11 @@ impl Parse {
for path in &paths {
let path = Path::new(&path);
let language =
loader.select_language(path, current_dir, self.scope.as_deref())?;
let language = loader
.select_language(path, current_dir, self.scope.as_deref())
.with_context(|| {
anyhow!("Failed to load langauge for path \"{}\"", path.display())
})?;
parse::parse_file_at_path(
&mut parser,