Skip to content

Commit

Permalink
[cli] Replace unwraps with better error handling (#15061)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored Oct 23, 2024
1 parent 321bbd2 commit 31f3820
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions crates/aptos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to the Aptos CLI will be captured in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format set out by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased
- [`Fix`] Remove unwraps to make outputs go through regular error handling

## [4.2.5] - 2024/10/23
- Bump to resolve issue with release version inconsistency.
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/move_tool/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl FmtCommand {
} else {
None
};
let package_path = dir_default_to_current(package_opt.clone()).unwrap();
let package_path = dir_default_to_current(package_opt.clone())?;
let root_res = SourcePackageLayout::try_find_root(&package_path.clone());
if let Ok(root_package_path) = root_res {
let mut path_vec = vec![];
Expand Down
23 changes: 8 additions & 15 deletions crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,7 @@ impl TryInto<PackagePublicationData> for &PublishPackage {
type Error = CliError;

fn try_into(self) -> Result<PackagePublicationData, Self::Error> {
let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;

let package_publication_data =
create_package_publication_data(package, PublishType::AccountDeploy, None)?;
Expand Down Expand Up @@ -815,8 +814,7 @@ impl AsyncTryInto<ChunkedPublishPayloads> for &PublishPackage {
type Error = CliError;

async fn async_try_into(self) -> Result<ChunkedPublishPayloads, Self::Error> {
let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;

let chunked_publish_payloads =
create_chunked_publish_payloads(package, PublishType::AccountDeploy, None)?;
Expand Down Expand Up @@ -1146,8 +1144,7 @@ impl CliCommand<TransactionSummary> for CreateObjectAndPublishPackage {
let mock_object_address = AccountAddress::from_hex_literal("0xcafe").unwrap();
self.move_options
.add_named_address(self.address_name.clone(), mock_object_address.to_string());
let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;
let mock_payloads =
create_chunked_publish_payloads(package, PublishType::AccountDeploy, None)?
.payloads;
Expand All @@ -1162,8 +1159,7 @@ impl CliCommand<TransactionSummary> for CreateObjectAndPublishPackage {
self.move_options
.add_named_address(self.address_name, object_address.to_string());

let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;
let message = format!(
"Do you want to publish this package at object address {}",
object_address
Expand Down Expand Up @@ -1246,7 +1242,7 @@ impl CliCommand<TransactionSummary> for UpgradeObjectPackage {

async fn execute(self) -> CliTypedResult<TransactionSummary> {
let built_package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
build_package_options(&self.move_options, &self.included_artifacts_args)?;
let url = self
.txn_options
.rest_options
Expand Down Expand Up @@ -1357,8 +1353,7 @@ impl CliCommand<TransactionSummary> for DeployObjectCode {
let mock_object_address = AccountAddress::from_hex_literal("0xcafe").unwrap();
self.move_options
.add_named_address(self.address_name.clone(), mock_object_address.to_string());
let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;
let mock_payloads =
create_chunked_publish_payloads(package, PublishType::AccountDeploy, None)?
.payloads;
Expand All @@ -1373,8 +1368,7 @@ impl CliCommand<TransactionSummary> for DeployObjectCode {
self.move_options
.add_named_address(self.address_name, object_address.to_string());

let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;
let message = format!(
"Do you want to deploy this package at object address {}",
object_address
Expand Down Expand Up @@ -1463,8 +1457,7 @@ impl CliCommand<TransactionSummary> for UpgradeCodeObject {
self.move_options
.add_named_address(self.address_name, self.object_address.to_string());

let package =
build_package_options(&self.move_options, &self.included_artifacts_args).unwrap();
let package = build_package_options(&self.move_options, &self.included_artifacts_args)?;
let url = self
.txn_options
.rest_options
Expand Down

0 comments on commit 31f3820

Please sign in to comment.