From 32a3c76869dedbf1003bae1f41267be8579a2b31 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Fri, 26 Jan 2024 07:48:51 +0800 Subject: [PATCH] refactor(sozo-migrate): de-debug error formatting (#1454) * fix * add verbose print on errors that can hide starknet data Currently, there is some data missing to be printed out by starknet-rs. ContractError reason for instance is never printed. The idea here is to have a bit more context with sozo if a user is stuck during migration. This commit starts work for the #1409 issue to add more logging to sozo. * remove debug printing in anyhow error --------- Co-authored-by: glihm --- bin/sozo/src/ops/migration/mod.rs | 51 +++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/bin/sozo/src/ops/migration/mod.rs b/bin/sozo/src/ops/migration/mod.rs index 85ff2f9166..c2cba7768e 100644 --- a/bin/sozo/src/ops/migration/mod.rs +++ b/bin/sozo/src/ops/migration/mod.rs @@ -219,7 +219,10 @@ where Some(manifest) } Err(ManifestError::RemoteWorldNotFound) => None, - Err(e) => return Err(anyhow!("Failed to build remote World state: {e}")), + Err(e) => { + ui.verbose(format!("{e:?}")); + return Err(anyhow!("Failed to build remote World state: {e}")); + } } } else { None @@ -295,7 +298,11 @@ where WorldContract::new(addr, &migrator) .set_executor(&executor.contract_address.into()) .send() - .await?; + .await + .map_err(|e| { + ui.verbose(format!("{e:?}")); + e + })?; TransactionWaiter::new(transaction_hash, migrator.provider()).await?; @@ -321,7 +328,10 @@ where Err(MigrationError::ClassAlreadyDeclared) => { ui.print_sub(format!("Already declared: {:#x}", base.diff.local)); } - Err(e) => return Err(e.into()), + Err(e) => { + ui.verbose(format!("{e:?}")); + return Err(e.into()); + } }; } None => {} @@ -337,7 +347,10 @@ where ]; deploy_contract(world, "world", calldata.clone(), migrator, &ui, &txn_config) .await - .map_err(|e| anyhow!("Failed to deploy world: {e}"))?; + .map_err(|e| { + ui.verbose(format!("{e:?}")); + anyhow!("Failed to deploy world: {e}") + })?; ui.print_sub(format!("Contract address: {:#x}", world.contract_address)); @@ -352,7 +365,10 @@ where .set_metadata_uri(&FieldElement::ZERO, &encoded_uri) .send() .await - .map_err(|e| anyhow!("Failed to set World metadata: {e}"))?; + .map_err(|e| { + ui.verbose(format!("{e:?}")); + anyhow!("Failed to set World metadata: {e}") + })?; ui.print_sub(format!("Set Metadata transaction: {:#x}", transaction_hash)); ui.print_sub(format!("Metadata uri: ipfs://{hash}")); @@ -416,7 +432,10 @@ where Err(MigrationError::ContractAlreadyDeployed(contract_address)) => { Ok(ContractDeploymentOutput::AlreadyDeployed(contract_address)) } - Err(e) => Err(anyhow!("Failed to migrate {}: {:?}", contract_id, e)), + Err(e) => { + ui.verbose(format!("{e:?}")); + Err(anyhow!("Failed to migrate {contract_id}: {e}")) + } } } @@ -457,7 +476,10 @@ where ui.print_sub(format!("Already declared: {:#x}", c.diff.local)); continue; } - Err(e) => bail!("Failed to declare model {}: {e}", c.diff.name), + Err(e) => { + ui.verbose(format!("{e:?}")); + bail!("Failed to declare model {}: {e}", c.diff.name) + } } ui.print_sub(format!("Class hash: {:#x}", c.diff.local)); @@ -471,11 +493,11 @@ where .map(|c| world.register_model_getcall(&c.diff.local.into())) .collect::>(); - let InvokeTransactionResult { transaction_hash } = migrator - .execute(calls) - .send() - .await - .map_err(|e| anyhow!("Failed to register models to World: {e:?}"))?; + let InvokeTransactionResult { transaction_hash } = + migrator.execute(calls).send().await.map_err(|e| { + ui.verbose(format!("{e:?}")); + anyhow!("Failed to register models to World: {e}") + })?; TransactionWaiter::new(transaction_hash, migrator.provider()).await?; @@ -534,7 +556,10 @@ where ui.print_sub(format!("Already deployed: {:#x}", contract_address)); deploy_output.push(None); } - Err(e) => return Err(anyhow!("Failed to migrate {}: {:?}", name, e)), + Err(e) => { + ui.verbose(format!("{e:?}")); + return Err(anyhow!("Failed to migrate {name}: {e}")); + } } }