Skip to content

Commit d80bbc9

Browse files
committed
fix: surface anyhow error chains in gnd output
1 parent a0d6eeb commit d80bbc9

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

gnd/src/commands/build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ fn create_ipfs_manifest(
486486
let manifest_str = fs::read_to_string(&manifest_path)
487487
.with_context(|| format!("Failed to read manifest: {}", manifest_path.display()))?;
488488

489-
let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)?;
489+
let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)
490+
.with_context(|| format!("Failed to parse manifest: {}", manifest_path.display()))?;
490491

491492
// Update schema path to IPFS reference
492493
if let Some(schema_path) = &manifest.schema {
@@ -747,7 +748,8 @@ fn write_output_manifest(
747748
let manifest_str = fs::read_to_string(manifest_path)
748749
.with_context(|| format!("Failed to read manifest: {:?}", manifest_path))?;
749750

750-
let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)?;
751+
let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)
752+
.with_context(|| format!("Failed to parse manifest: {:?}", manifest_path))?;
751753

752754
// Update schema path
753755
if let Some(schema) = value.get_mut("schema")

gnd/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ async fn main() -> Result<()> {
263263
};
264264

265265
if let Err(e) = res {
266-
eprintln!("Error: {}", e);
266+
eprintln!("Error: {:#}", e);
267267
std::process::exit(1);
268268
}
269269

gnd/src/manifest.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,47 @@ dataSources:
697697
);
698698
}
699699

700+
#[test]
701+
fn test_load_manifest_error_chain_includes_parse_context_and_cause() {
702+
let temp_dir = TempDir::new().unwrap();
703+
let manifest_path = temp_dir.path().join("subgraph.yaml");
704+
705+
let manifest_content = r#"
706+
specVersion: 0.0.4
707+
schema: {}
708+
dataSources:
709+
- kind: ethereum/contract
710+
name: Token
711+
network: mainnet
712+
source:
713+
abi: ERC20
714+
mapping:
715+
kind: ethereum/events
716+
apiVersion: 0.0.6
717+
language: wasm/assemblyscript
718+
file: ./src/mapping.ts
719+
entities:
720+
- MyEntity
721+
abis:
722+
- name: ERC20
723+
file: ./abis/ERC20.json
724+
"#;
725+
726+
fs::write(&manifest_path, manifest_content).unwrap();
727+
728+
let err_chain = format!("{:#}", load_manifest(&manifest_path).unwrap_err());
729+
assert!(
730+
err_chain.contains("Failed to parse manifest"),
731+
"Error chain should include manifest parse context, got: {}",
732+
err_chain
733+
);
734+
assert!(
735+
err_chain.contains("missing field") && err_chain.contains("file"),
736+
"Error chain should include the underlying serde_yaml cause, got: {}",
737+
err_chain
738+
);
739+
}
740+
700741
#[test]
701742
fn test_load_manifest_missing_mapping_abis_fails() {
702743
let temp_dir = TempDir::new().unwrap();

gnd/src/watch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
{
4747
// Do initial run
4848
if let Err(e) = on_change().await {
49-
eprintln!("Error during initial run: {}", e);
49+
eprintln!("Error during initial run: {:#}", e);
5050
}
5151

5252
println!("\n{}", initial_msg);
@@ -101,7 +101,7 @@ where
101101
println!("\nFile change detected: {}\n", changed);
102102

103103
if let Err(e) = on_change().await {
104-
eprintln!("Error during rebuild: {}", e);
104+
eprintln!("Error during rebuild: {:#}", e);
105105
}
106106
}
107107
}

0 commit comments

Comments
 (0)