diff --git a/gnd/src/commands/build.rs b/gnd/src/commands/build.rs index b33731330aa..6a4b855e106 100644 --- a/gnd/src/commands/build.rs +++ b/gnd/src/commands/build.rs @@ -486,7 +486,8 @@ fn create_ipfs_manifest( let manifest_str = fs::read_to_string(&manifest_path) .with_context(|| format!("Failed to read manifest: {}", manifest_path.display()))?; - let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)?; + let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str) + .with_context(|| format!("Failed to parse manifest: {}", manifest_path.display()))?; // Update schema path to IPFS reference if let Some(schema_path) = &manifest.schema { @@ -747,7 +748,8 @@ fn write_output_manifest( let manifest_str = fs::read_to_string(manifest_path) .with_context(|| format!("Failed to read manifest: {:?}", manifest_path))?; - let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)?; + let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str) + .with_context(|| format!("Failed to parse manifest: {:?}", manifest_path))?; // Update schema path if let Some(schema) = value.get_mut("schema") diff --git a/gnd/src/main.rs b/gnd/src/main.rs index 092674e5da0..6def5a01922 100644 --- a/gnd/src/main.rs +++ b/gnd/src/main.rs @@ -263,7 +263,7 @@ async fn main() -> Result<()> { }; if let Err(e) = res { - eprintln!("Error: {}", e); + eprintln!("Error: {:#}", e); std::process::exit(1); } diff --git a/gnd/src/manifest.rs b/gnd/src/manifest.rs index 0221070edfe..4940b495455 100644 --- a/gnd/src/manifest.rs +++ b/gnd/src/manifest.rs @@ -697,6 +697,47 @@ dataSources: ); } + #[test] + fn test_load_manifest_error_chain_includes_parse_context_and_cause() { + let temp_dir = TempDir::new().unwrap(); + let manifest_path = temp_dir.path().join("subgraph.yaml"); + + let manifest_content = r#" +specVersion: 0.0.4 +schema: {} +dataSources: + - kind: ethereum/contract + name: Token + network: mainnet + source: + abi: ERC20 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + file: ./src/mapping.ts + entities: + - MyEntity + abis: + - name: ERC20 + file: ./abis/ERC20.json +"#; + + fs::write(&manifest_path, manifest_content).unwrap(); + + let err_chain = format!("{:#}", load_manifest(&manifest_path).unwrap_err()); + assert!( + err_chain.contains("Failed to parse manifest"), + "Error chain should include manifest parse context, got: {}", + err_chain + ); + assert!( + err_chain.contains("missing field") && err_chain.contains("file"), + "Error chain should include the underlying serde_yaml cause, got: {}", + err_chain + ); + } + #[test] fn test_load_manifest_missing_mapping_abis_fails() { let temp_dir = TempDir::new().unwrap(); diff --git a/gnd/src/watch.rs b/gnd/src/watch.rs index cf1d3e4ea31..7814a55b467 100644 --- a/gnd/src/watch.rs +++ b/gnd/src/watch.rs @@ -46,7 +46,7 @@ where { // Do initial run if let Err(e) = on_change().await { - eprintln!("Error during initial run: {}", e); + eprintln!("Error during initial run: {:#}", e); } println!("\n{}", initial_msg); @@ -101,7 +101,7 @@ where println!("\nFile change detected: {}\n", changed); if let Err(e) = on_change().await { - eprintln!("Error during rebuild: {}", e); + eprintln!("Error during rebuild: {:#}", e); } } }