From 0c83a5d03e567dedc63e39244b345cfa26ec2aeb Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Sat, 2 Aug 2025 05:52:54 -0400 Subject: [PATCH] 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 `, 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. (cherry picked from commit 9ced6172de6737591a164f1d5b486588f3b98fc6) --- cli/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index ae9be31b..ecb638f7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -965,8 +965,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,