From 79ac5af04c2d05a6a8117472daa958a8bec4afef Mon Sep 17 00:00:00 2001 From: stefan-mysten <135084671+stefan-mysten@users.noreply.github.com> Date: Thu, 27 Feb 2025 09:53:23 -0800 Subject: [PATCH] Rework errors around fetching move packages --- crates/sui/Cargo.toml | 1 + crates/sui/src/client_commands.rs | 44 ++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/crates/sui/Cargo.toml b/crates/sui/Cargo.toml index 677217f40daf6..4215949e13e91 100644 --- a/crates/sui/Cargo.toml +++ b/crates/sui/Cargo.toml @@ -99,6 +99,7 @@ move-vm-config.workspace = true move-ir-types.workspace = true move-command-line-common.workspace = true move-cli.workspace = true +move-symbol-pool.workspace = true [target.'cfg(not(target_env = "msvc"))'.dependencies] jemalloc-ctl.workspace = true diff --git a/crates/sui/src/client_commands.rs b/crates/sui/src/client_commands.rs index b05cb796ac241..0061668efb45a 100644 --- a/crates/sui/src/client_commands.rs +++ b/crates/sui/src/client_commands.rs @@ -94,6 +94,7 @@ use tabled::{ }, }; +use move_symbol_pool::Symbol; use sui_types::digests::ChainIdentifier; use tracing::{debug, info}; @@ -3112,22 +3113,46 @@ async fn check_protocol_version_and_warn(client: &SuiClient) -> Result<(), anyho async fn fetch_move_packages( client: &SuiClient, package_ids: &[ObjectID], + pkg_id_to_name: &BTreeMap<&ObjectID, &Symbol>, ) -> Result, anyhow::Error> { let objects = client .read_api() .multi_get_object_with_options(package_ids.to_vec(), SuiObjectDataOptions::bcs_lossless()) - .await - .map_err(|e| anyhow!("{e}"))?; + .await?; objects .into_iter() .map(|o| { - let o = o.into_object().map_err(|e| anyhow!("{e}"))?; + let o = o.into_object().map_err(|e| match e { + sui_types::error::SuiObjectResponseError::NotExists { object_id } => { + anyhow!( + "Package {:?} with object ID {object_id} does not exist", + pkg_id_to_name.get(&object_id) + ) + } + sui_types::error::SuiObjectResponseError::Deleted { + object_id, + version, + digest, + } => { + anyhow!( + "Package {:?} with object ID {object_id} was deleted at version {version} \ + with digest {digest}", + pkg_id_to_name.get(&object_id) + ) + } + _ => anyhow!("Error fetching package: {e}"), + })?; + let Some(SuiRawData::Package(p)) = o.bcs else { - bail!("Expected SuiRawData::Package but got something else"); + bail!( + "Expected package {:?} with object ID {} but got something else", + pkg_id_to_name.get(&o.object_id), + o.object_id + ); }; p.to_move_package(u64::MAX /* safe as this pkg comes from the network */) - .map_err(|e| anyhow!("{e}")) + .map_err(|e| anyhow!(e)) }) .collect() } @@ -3139,7 +3164,11 @@ pub(crate) async fn pkg_tree_shake( compiled_package: &mut CompiledPackage, ) -> Result<(), anyhow::Error> { let pkgs = compiled_package.find_immediate_deps_pkgs_to_keep(with_unpublished_dependencies)?; - let pkg_ids: Vec<_> = pkgs.clone().into_values().collect(); + let pkg_ids = pkgs.values().cloned().collect::>(); + let pkg_id_to_name = pkgs + .iter() + .map(|(name, id)| (id, name)) + .collect::>(); let pkg_name_to_orig_id: BTreeMap<_, _> = compiled_package .package @@ -3148,7 +3177,8 @@ pub(crate) async fn pkg_tree_shake( .map(|(pkg_name, module)| (pkg_name, ObjectID::from(module.unit.address.into_inner()))) .collect(); - let published_deps_packages = fetch_move_packages(client, &pkg_ids).await?; + let published_deps_packages = fetch_move_packages(client, &pkg_ids, &pkg_id_to_name).await?; + let linkage_table_ids = published_deps_packages .iter() .flat_map(|pkg| {