Skip to content

Commit

Permalink
fix(parser): add anyhow::Context messages to `get_patterns_from_fil…
Browse files Browse the repository at this point in the history
…e()` awaits if the function fails to find the repo root or fails to read the file path

fixes #423
  • Loading branch information
Alex-ley-scrub committed Oct 23, 2024
1 parent bad0783 commit 66eb89b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/gritmodule/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,17 @@ pub async fn get_patterns_from_file(
ext: PatternFileExt,
overrides: GritDefinitionOverrides,
) -> Result<Vec<ModuleGritPattern>> {
let repo_root = find_repo_root_from(path.clone()).await?;
let content = fs::read_to_string(&path).await?;
let path_str = path.to_string_lossy();
let repo_root = find_repo_root_from(path.clone()).await.context(format!(
"Failed to find repository root from path {}",
path_str
))?;
let content = fs::read_to_string(&path).await.context(format!(
"Failed to find pattern at {}. Does it exist?",
extract_relative_path(&path_str, &repo_root)
))?;
let mut file = RichFile {
path: path.to_string_lossy().to_string(),
path: path_str.to_string(),
content,
};
ext.get_patterns(&mut file, &source_module, &repo_root, overrides)
Expand Down

0 comments on commit 66eb89b

Please sign in to comment.