From e6e756e9aec69f0dd9105f159860ae0d0b8e9b29 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Wed, 3 Jul 2024 19:07:22 +0000 Subject: [PATCH] Improve Anchor and Hardhat error messages --- backends/src/anchor/mod.rs | 5 +++-- backends/src/parsing.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backends/src/anchor/mod.rs b/backends/src/anchor/mod.rs index 4e89ca66..c52a06e2 100644 --- a/backends/src/anchor/mod.rs +++ b/backends/src/anchor/mod.rs @@ -1,5 +1,5 @@ use super::{ts, OutputAccessors, OutputStrippedOfAnsiScapes, ParseAdapter, ParseHigh, RunHigh}; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; use log::debug; use necessist_core::{ framework::{Interface, Postprocess, SourceFileTestSpanMap}, @@ -34,7 +34,8 @@ impl Anchor { pub fn new(context: &LightContext) -> Result { let anchor_toml = context.root.join("Anchor.toml"); - let contents = read_to_string(&anchor_toml)?; + let contents = read_to_string(&anchor_toml) + .with_context(|| format!(r#"Failed to read "{}""#, anchor_toml.display()))?; let mut document = contents.parse::()?; let (prefix, suffix) = edit_test_script(&mut document, parse_test_value)?; Ok(Self { diff --git a/backends/src/parsing.rs b/backends/src/parsing.rs index 26c11c39..f2f50ab5 100644 --- a/backends/src/parsing.rs +++ b/backends/src/parsing.rs @@ -1,5 +1,5 @@ use super::{GenericVisitor, ParseHigh}; -use anyhow::Result; +use anyhow::{Context, Result}; use heck::ToKebabCase; use necessist_core::{ config, @@ -381,7 +381,8 @@ impl ParseHigh for ParseAdapter { if source_files.is_empty() { for entry in walk_dir_results { - let entry = entry?; + let entry = entry + .with_context(|| format!(r#"Failed to walk "{}""#, context.root.display()))?; let path = entry.path(); if !path.is_file() {