Skip to content

Commit

Permalink
Rework errors around fetching move packages
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-mysten committed Feb 27, 2025
1 parent 51cb5b1 commit 79ac5af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/sui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 37 additions & 7 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ use tabled::{
},
};

use move_symbol_pool::Symbol;
use sui_types::digests::ChainIdentifier;
use tracing::{debug, info};

Expand Down Expand Up @@ -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<Vec<MovePackage>, 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()
}
Expand All @@ -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::<Vec<_>>();
let pkg_id_to_name = pkgs
.iter()
.map(|(name, id)| (id, name))
.collect::<BTreeMap<_, _>>();

let pkg_name_to_orig_id: BTreeMap<_, _> = compiled_package
.package
Expand All @@ -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| {
Expand Down

0 comments on commit 79ac5af

Please sign in to comment.