Skip to content

Commit

Permalink
refactor(sozo-migrate): de-debug error formatting (dojoengine#1454)
Browse files Browse the repository at this point in the history
* 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 dojoengine#1409 issue to add more logging
to sozo.

* remove debug printing in anyhow error

---------

Co-authored-by: glihm <[email protected]>
  • Loading branch information
kariy and glihm committed Jan 25, 2024
1 parent 2ec18ce commit 32a3c76
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions bin/sozo/src/ops/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?;

Expand All @@ -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 => {}
Expand All @@ -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));

Expand All @@ -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}"));
Expand Down Expand Up @@ -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}"))
}
}
}

Expand Down Expand Up @@ -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));
Expand All @@ -471,11 +493,11 @@ where
.map(|c| world.register_model_getcall(&c.diff.local.into()))
.collect::<Vec<_>>();

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?;

Expand Down Expand Up @@ -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}"));
}
}
}

Expand Down

0 comments on commit 32a3c76

Please sign in to comment.