From 3d865949c2f9f0cb61031bcc2b9e81a4ca623109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 23 May 2023 19:35:12 +0200 Subject: [PATCH] fix: better error message for malformed glob (#19225) Before: ``` $ cargo run -- test "foo/*******/bar.ts" error: Pattern syntax error near position 6: wildcards are either regular `*` or recursive `**` ``` After: ``` $ cargo run -- test "foo/*******/bar.ts" error: Failed to expand glob: "foo/*******/bar.ts" Caused by: Pattern syntax error near position 6: wildcards are either regular `*` or recursive `**` ``` --------- Co-authored-by: David Sherret --- cli/args/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 513d4b39e0..8b3d793087 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1343,7 +1343,8 @@ fn expand_globs(paths: &[PathBuf]) -> Result, AnyError> { // true because it copies with sh does—these files are considered "hidden" require_literal_leading_dot: true, }, - )?; + ) + .with_context(|| format!("Failed to expand glob: \"{}\"", path_str))?; for globbed_path_result in globbed_paths { new_paths.push(globbed_path_result?); @@ -1592,6 +1593,16 @@ mod test { temp_dir.write("pages/[id].ts", ""); + let error = resolve_files( + Some(FilesConfig { + include: vec![temp_dir.path().join("data/**********.ts")], + exclude: vec![], + }), + None, + ) + .unwrap_err(); + assert!(error.to_string().starts_with("Failed to expand glob")); + let resolved_files = resolve_files( Some(FilesConfig { include: vec![