From 6041a9de1eb9bf3f7cf910029f0c8ba0d2a90af1 Mon Sep 17 00:00:00 2001 From: Eric Swanson Date: Thu, 17 Aug 2023 15:16:19 -0700 Subject: [PATCH] refactor: concrete error type for Identity::new --- .../src/error/identity/create_new_identity.rs | 3 +- .../src/error/identity/export_identity.rs | 6 ++-- .../get_identity_config_or_default.rs | 8 +++++ .../instantiate_identity_from_name.rs | 15 +++++++++ .../src/error/identity/load_identity.rs | 12 +++++++ src/dfx-core/src/error/identity/load_pem.rs | 12 +++++++ .../src/error/identity/load_pem_from_file.rs | 13 ++++++++ .../src/error/identity/load_pem_identity.rs | 8 +++++ src/dfx-core/src/error/identity/mod.rs | 31 +++++-------------- .../error/identity/new_hardware_identity.rs | 8 +++++ .../src/error/identity/new_identity.rs | 16 ++++++++++ .../src/error/identity/rename_identity.rs | 6 ++-- src/dfx-core/src/identity/identity_manager.rs | 31 +++++++++++++------ src/dfx-core/src/identity/mod.rs | 29 ++++++++++++----- src/dfx-core/src/identity/pem_safekeeping.rs | 17 +++++----- src/dfx/src/commands/canister/create.rs | 2 +- .../src/commands/canister/update_settings.rs | 2 +- 17 files changed, 165 insertions(+), 54 deletions(-) create mode 100644 src/dfx-core/src/error/identity/get_identity_config_or_default.rs create mode 100644 src/dfx-core/src/error/identity/instantiate_identity_from_name.rs create mode 100644 src/dfx-core/src/error/identity/load_identity.rs create mode 100644 src/dfx-core/src/error/identity/load_pem.rs create mode 100644 src/dfx-core/src/error/identity/load_pem_from_file.rs create mode 100644 src/dfx-core/src/error/identity/load_pem_identity.rs create mode 100644 src/dfx-core/src/error/identity/new_hardware_identity.rs create mode 100644 src/dfx-core/src/error/identity/new_identity.rs diff --git a/src/dfx-core/src/error/identity/create_new_identity.rs b/src/dfx-core/src/error/identity/create_new_identity.rs index b7b454618a..0f0739fee4 100644 --- a/src/dfx-core/src/error/identity/create_new_identity.rs +++ b/src/dfx-core/src/error/identity/create_new_identity.rs @@ -1,6 +1,7 @@ use crate::error::fs::FsError; use crate::error::identity::convert_mnemonic_to_key::ConvertMnemonicToKeyError; use crate::error::identity::generate_key::GenerateKeyError; +use crate::error::identity::load_pem_from_file::LoadPemFromFileError; use crate::error::identity::remove_identity::RemoveIdentityError; use crate::error::identity::save_pem::SavePemError; use crate::error::identity::IdentityError; @@ -36,7 +37,7 @@ pub enum CreateNewIdentityError { IdentityAlreadyExists(), #[error("Failed to load pem file: {0}")] - LoadPemFromFileFailed(IdentityError), + LoadPemFromFileFailed(LoadPemFromFileError), #[error("Failed to remove identity: {0}")] RemoveIdentityFailed(RemoveIdentityError), diff --git a/src/dfx-core/src/error/identity/export_identity.rs b/src/dfx-core/src/error/identity/export_identity.rs index ff21d6e6cd..9882ee9e7f 100644 --- a/src/dfx-core/src/error/identity/export_identity.rs +++ b/src/dfx-core/src/error/identity/export_identity.rs @@ -1,3 +1,5 @@ +use crate::error::identity::get_identity_config_or_default::GetIdentityConfigOrDefaultError; +use crate::error::identity::load_pem::LoadPemError; use crate::error::identity::IdentityError; use std::string::FromUtf8Error; use thiserror::Error; @@ -5,13 +7,13 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum ExportIdentityError { #[error("Failed to get identity config: {0}")] - GetIdentityConfigFailed(IdentityError), + GetIdentityConfigFailed(GetIdentityConfigOrDefaultError), #[error("The specified identity does not exist: {0}")] IdentityDoesNotExist(IdentityError), #[error("Failed to load pem file: {0}")] - LoadPemFailed(IdentityError), + LoadPemFailed(LoadPemError), #[error("Could not translate pem file to text: {0}")] TranslatePemContentToTextFailed(FromUtf8Error), diff --git a/src/dfx-core/src/error/identity/get_identity_config_or_default.rs b/src/dfx-core/src/error/identity/get_identity_config_or_default.rs new file mode 100644 index 0000000000..d7cd9fe0fc --- /dev/null +++ b/src/dfx-core/src/error/identity/get_identity_config_or_default.rs @@ -0,0 +1,8 @@ +use crate::error::structured_file::StructuredFileError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum GetIdentityConfigOrDefaultError { + #[error("Failed to load configuration for identity '{0}': {1}")] + LoadIdentityConfigurationFailed(String, StructuredFileError), +} diff --git a/src/dfx-core/src/error/identity/instantiate_identity_from_name.rs b/src/dfx-core/src/error/identity/instantiate_identity_from_name.rs new file mode 100644 index 0000000000..139dcae094 --- /dev/null +++ b/src/dfx-core/src/error/identity/instantiate_identity_from_name.rs @@ -0,0 +1,15 @@ +use crate::error::identity::load_identity::LoadIdentityError; +use crate::error::identity::IdentityError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum InstantiateIdentityFromNameError { + #[error("Failed to get principal of identity: {0}")] + GetIdentityPrincipalFailed(String), + + #[error("Failed to load identity: {0}")] + LoadIdentityFailed(LoadIdentityError), + + #[error("Identity must exist: {0}")] + RequireIdentityExistsFailed(IdentityError), +} diff --git a/src/dfx-core/src/error/identity/load_identity.rs b/src/dfx-core/src/error/identity/load_identity.rs new file mode 100644 index 0000000000..b237ed2c96 --- /dev/null +++ b/src/dfx-core/src/error/identity/load_identity.rs @@ -0,0 +1,12 @@ +use crate::error::identity::get_identity_config_or_default::GetIdentityConfigOrDefaultError; +use crate::error::identity::new_identity::NewIdentityError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum LoadIdentityError { + #[error("Failed to get identity config: {0}")] + GetIdentityConfigOrDefaultFailed(GetIdentityConfigOrDefaultError), + + #[error("Failed to instantiate identity: {0}")] + NewIdentityFailed(NewIdentityError), +} diff --git a/src/dfx-core/src/error/identity/load_pem.rs b/src/dfx-core/src/error/identity/load_pem.rs new file mode 100644 index 0000000000..5cf73dea45 --- /dev/null +++ b/src/dfx-core/src/error/identity/load_pem.rs @@ -0,0 +1,12 @@ +use crate::error::identity::load_pem_from_file::LoadPemFromFileError; +use crate::error::keyring::KeyringError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum LoadPemError { + #[error("Failed to load PEM file from file : {0}")] + LoadFromFileFailed(LoadPemFromFileError), + + #[error("Failed to load PEM file from keyring for identity '{0}': {1}")] + LoadFromKeyringFailed(Box, KeyringError), +} diff --git a/src/dfx-core/src/error/identity/load_pem_from_file.rs b/src/dfx-core/src/error/identity/load_pem_from_file.rs new file mode 100644 index 0000000000..6fcfa57229 --- /dev/null +++ b/src/dfx-core/src/error/identity/load_pem_from_file.rs @@ -0,0 +1,13 @@ +use crate::error::encryption::EncryptionError; +use crate::error::fs::FsError; +use std::path::PathBuf; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum LoadPemFromFileError { + #[error("Failed to decrypt PEM file: {0}")] + DecryptPemFileFailed(PathBuf, EncryptionError), + + #[error("Failed to read pem file: {0}")] + ReadPemFileFailed(FsError), +} diff --git a/src/dfx-core/src/error/identity/load_pem_identity.rs b/src/dfx-core/src/error/identity/load_pem_identity.rs new file mode 100644 index 0000000000..74033d3afb --- /dev/null +++ b/src/dfx-core/src/error/identity/load_pem_identity.rs @@ -0,0 +1,8 @@ +use ic_agent::identity::PemError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum LoadPemIdentityError { + #[error("Cannot read identity file '{0}': {1:#}")] + ReadIdentityFileFailed(String, Box), +} diff --git a/src/dfx-core/src/error/identity/mod.rs b/src/dfx-core/src/error/identity/mod.rs index 760d08f8d6..346ce8e569 100644 --- a/src/dfx-core/src/error/identity/mod.rs +++ b/src/dfx-core/src/error/identity/mod.rs @@ -2,8 +2,16 @@ pub mod convert_mnemonic_to_key; pub mod create_new_identity; pub mod export_identity; pub mod generate_key; +pub mod get_identity_config_or_default; pub mod get_legacy_credentials_pem_path; pub mod initialize_identity_manager; +pub mod instantiate_identity_from_name; +pub mod load_identity; +pub mod load_pem; +pub mod load_pem_from_file; +pub mod load_pem_identity; +pub mod new_hardware_identity; +pub mod new_identity; pub mod new_identity_manager; pub mod remove_identity; pub mod rename_identity; @@ -13,20 +21,15 @@ pub mod write_pem_to_file; use crate::error::config::ConfigError; use crate::error::encryption::EncryptionError; use crate::error::fs::FsError; -use crate::error::keyring::KeyringError; use crate::error::structured_file::StructuredFileError; use crate::error::wallet_config::WalletConfigError; use ic_agent::export::PrincipalError; use ic_agent::identity::PemError; -use ic_identity_hsm::HardwareIdentityError; use std::path::PathBuf; use thiserror::Error; #[derive(Error, Debug)] pub enum IdentityError { - #[error("Failed to decrypt PEM file: {0}")] - DecryptPemFileFailed(PathBuf, EncryptionError), - #[error("Failed to ensure identity configuration directory exists: {0}")] EnsureIdentityConfigurationDirExistsFailed(FsError), @@ -39,30 +42,12 @@ pub enum IdentityError { #[error("Failed to get shared network data directory: {0}")] GetSharedNetworkDataDirectoryFailed(ConfigError), - #[error("Failed to get principal of identity: {0}")] - GetIdentityPrincipalFailed(String), - #[error("Identity {0} does not exist at '{1}'.")] IdentityDoesNotExist(String, PathBuf), - #[error("Failed to instantiate hardware identity for identity '{0}': {1}.")] - InstantiateHardwareIdentityFailed(String, Box), - - #[error("Failed to load configuration for identity '{0}': {1}")] - LoadIdentityConfigurationFailed(String, StructuredFileError), - - #[error("Failed to load PEM file from keyring for identity '{0}': {1}")] - LoadPemFromKeyringFailed(Box, KeyringError), - #[error("Failed to read principal from id '{0}': {1}")] ParsePrincipalFromIdFailed(String, PrincipalError), - #[error("Cannot read identity file '{0}': {1:#}")] - ReadIdentityFileFailed(String, Box), - - #[error("Failed to read pem file: {0}")] - ReadPemFileFailed(FsError), - #[error("Failed to rename '{0}' to '{1}' in the global wallet config: {2}")] RenameWalletFailed(Box, Box, WalletConfigError), diff --git a/src/dfx-core/src/error/identity/new_hardware_identity.rs b/src/dfx-core/src/error/identity/new_hardware_identity.rs new file mode 100644 index 0000000000..30aefa112e --- /dev/null +++ b/src/dfx-core/src/error/identity/new_hardware_identity.rs @@ -0,0 +1,8 @@ +use ic_identity_hsm::HardwareIdentityError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum NewHardwareIdentityError { + #[error("Failed to instantiate hardware identity for identity '{0}': {1}.")] + InstantiateHardwareIdentityFailed(String, Box), +} diff --git a/src/dfx-core/src/error/identity/new_identity.rs b/src/dfx-core/src/error/identity/new_identity.rs new file mode 100644 index 0000000000..f46c0a65d3 --- /dev/null +++ b/src/dfx-core/src/error/identity/new_identity.rs @@ -0,0 +1,16 @@ +use crate::error::identity::load_pem::LoadPemError; +use crate::error::identity::load_pem_identity::LoadPemIdentityError; +use crate::error::identity::new_hardware_identity::NewHardwareIdentityError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum NewIdentityError { + #[error("Failed to load PEM: {0}")] + LoadPemFailed(LoadPemError), + + #[error("Failed to load PEM identity: {0}")] + LoadPemIdentityFailed(LoadPemIdentityError), + + #[error("Failed to instantiate hardware identity: {0}")] + NewHardwareIdentityFailed(NewHardwareIdentityError), +} diff --git a/src/dfx-core/src/error/identity/rename_identity.rs b/src/dfx-core/src/error/identity/rename_identity.rs index 9c267cabf1..211dbcd7b2 100644 --- a/src/dfx-core/src/error/identity/rename_identity.rs +++ b/src/dfx-core/src/error/identity/rename_identity.rs @@ -1,4 +1,6 @@ use crate::error::fs::FsError; +use crate::error::identity::get_identity_config_or_default::GetIdentityConfigOrDefaultError; +use crate::error::identity::load_pem::LoadPemError; use crate::error::identity::save_pem::SavePemError; use crate::error::identity::IdentityError; use crate::error::keyring::KeyringError; @@ -10,7 +12,7 @@ pub enum RenameIdentityError { CannotCreateAnonymousIdentity(), #[error("Failed to get identity config: {0}")] - GetIdentityConfigFailed(IdentityError), + GetIdentityConfigFailed(GetIdentityConfigOrDefaultError), #[error("Identity already exists.")] IdentityAlreadyExists(), @@ -19,7 +21,7 @@ pub enum RenameIdentityError { IdentityDoesNotExist(IdentityError), #[error("Failed to load pem: {0}")] - LoadPemFailed(IdentityError), + LoadPemFailed(LoadPemError), #[error("Failed to map wallets to renamed identity: {0}")] MapWalletsToRenamedIdentityFailed(IdentityError /*MapWalletsToRenamedIdentityError*/), diff --git a/src/dfx-core/src/identity/identity_manager.rs b/src/dfx-core/src/identity/identity_manager.rs index b4238534d7..9a8f7db47e 100644 --- a/src/dfx-core/src/identity/identity_manager.rs +++ b/src/dfx-core/src/identity/identity_manager.rs @@ -17,6 +17,8 @@ use crate::error::identity::export_identity::ExportIdentityError; use crate::error::identity::export_identity::ExportIdentityError::TranslatePemContentToTextFailed; use crate::error::identity::generate_key::GenerateKeyError; use crate::error::identity::generate_key::GenerateKeyError::GenerateFreshSecp256k1KeyFailed; +use crate::error::identity::get_identity_config_or_default::GetIdentityConfigOrDefaultError; +use crate::error::identity::get_identity_config_or_default::GetIdentityConfigOrDefaultError::LoadIdentityConfigurationFailed; use crate::error::identity::get_legacy_credentials_pem_path::GetLegacyCredentialsPemPathError; use crate::error::identity::get_legacy_credentials_pem_path::GetLegacyCredentialsPemPathError::GetLegacyPemPathFailed; use crate::error::identity::initialize_identity_manager::InitializeIdentityManagerError; @@ -24,6 +26,11 @@ use crate::error::identity::initialize_identity_manager::InitializeIdentityManag CreateIdentityDirectoryFailed, GenerateKeyFailed, MigrateLegacyIdentityFailed, WritePemToFileFailed, }; +use crate::error::identity::instantiate_identity_from_name::InstantiateIdentityFromNameError; +use crate::error::identity::instantiate_identity_from_name::InstantiateIdentityFromNameError::{ + GetIdentityPrincipalFailed, LoadIdentityFailed, +}; +use crate::error::identity::load_identity::LoadIdentityError; use crate::error::identity::new_identity_manager::NewIdentityManagerError; use crate::error::identity::new_identity_manager::NewIdentityManagerError::LoadIdentityManagerConfigurationFailed; use crate::error::identity::remove_identity::RemoveIdentityError; @@ -39,7 +46,6 @@ use crate::error::identity::rename_identity::RenameIdentityError::{ use crate::error::identity::IdentityError; use crate::error::identity::IdentityError::{ EnsureIdentityConfigurationDirExistsFailed, GenerateFreshEncryptionConfigurationFailed, - GetIdentityPrincipalFailed, LoadIdentityConfigurationFailed, SaveIdentityConfigurationFailed, }; use crate::error::structured_file::StructuredFileError; use crate::foundation::get_user_home; @@ -238,7 +244,7 @@ impl IdentityManager { pub fn instantiate_selected_identity( &mut self, log: &Logger, - ) -> Result, IdentityError> { + ) -> Result, InstantiateIdentityFromNameError> { let name = self.selected_identity.clone(); self.instantiate_identity_from_name(name.as_str(), log) } @@ -248,12 +254,16 @@ impl IdentityManager { &mut self, identity_name: &str, log: &Logger, - ) -> Result, IdentityError> { + ) -> Result, InstantiateIdentityFromNameError> { let identity = match identity_name { ANONYMOUS_IDENTITY_NAME => Box::new(DfxIdentity::anonymous()), identity_name => { - self.require_identity_exists(log, identity_name)?; - Box::new(self.load_identity(identity_name, log)?) + self.require_identity_exists(log, identity_name) + .map_err(InstantiateIdentityFromNameError::RequireIdentityExistsFailed)?; + Box::new( + self.load_identity(identity_name, log) + .map_err(LoadIdentityFailed)?, + ) } }; use ic_agent::identity::Identity; @@ -262,9 +272,12 @@ impl IdentityManager { Ok(identity) } - fn load_identity(&self, name: &str, log: &Logger) -> Result { - let config = self.get_identity_config_or_default(name)?; + fn load_identity(&self, name: &str, log: &Logger) -> Result { + let config = self + .get_identity_config_or_default(name) + .map_err(LoadIdentityError::GetIdentityConfigOrDefaultFailed)?; DfxIdentity::new(name, config, self.file_locations(), log) + .map_err(LoadIdentityError::NewIdentityFailed) } /// Create a new identity (name -> generated key) @@ -641,7 +654,7 @@ impl IdentityManager { pub fn get_identity_config_or_default( &self, identity: &str, - ) -> Result { + ) -> Result { let json_path = self.get_identity_json_path(identity); if json_path.exists() { load_json_file(&json_path) @@ -758,7 +771,7 @@ pub(super) fn save_identity_configuration( trace!(log, "Writing identity configuration to {}", path.display()); ensure_parent_dir_exists(path).map_err(EnsureIdentityConfigurationDirExistsFailed)?; - save_json_file(path, &config).map_err(SaveIdentityConfigurationFailed) + save_json_file(path, &config).map_err(IdentityError::SaveIdentityConfigurationFailed) } /// Removes the file if it exists. diff --git a/src/dfx-core/src/identity/mod.rs b/src/dfx-core/src/identity/mod.rs index ccee470205..1684258301 100644 --- a/src/dfx-core/src/identity/mod.rs +++ b/src/dfx-core/src/identity/mod.rs @@ -3,10 +3,14 @@ //! Wallets are a map of network-identity, but don't have their own types or manager //! type. use crate::config::directories::{get_config_dfx_dir_path, get_shared_network_data_directory}; +use crate::error::identity::load_pem_identity::LoadPemIdentityError; +use crate::error::identity::load_pem_identity::LoadPemIdentityError::ReadIdentityFileFailed; +use crate::error::identity::new_hardware_identity::NewHardwareIdentityError; +use crate::error::identity::new_hardware_identity::NewHardwareIdentityError::InstantiateHardwareIdentityFailed; +use crate::error::identity::new_identity::NewIdentityError; use crate::error::identity::IdentityError; use crate::error::identity::IdentityError::{ - GetConfigDirectoryFailed, GetSharedNetworkDataDirectoryFailed, - InstantiateHardwareIdentityFailed, ReadIdentityFileFailed, RenameWalletFailed, + GetConfigDirectoryFailed, GetSharedNetworkDataDirectoryFailed, RenameWalletFailed, }; use crate::error::wallet_config::WalletConfigError; use crate::error::wallet_config::WalletConfigError::{ @@ -74,7 +78,11 @@ impl Identity { } } - fn basic(name: &str, pem_content: &[u8], was_encrypted: bool) -> Result { + fn basic( + name: &str, + pem_content: &[u8], + was_encrypted: bool, + ) -> Result { let inner = Box::new( BasicIdentity::from_pem(pem_content) .map_err(|e| ReadIdentityFileFailed(name.into(), Box::new(e)))?, @@ -91,7 +99,7 @@ impl Identity { name: &str, pem_content: &[u8], was_encrypted: bool, - ) -> Result { + ) -> Result { let inner = Box::new( Secp256k1Identity::from_pem(pem_content) .map_err(|e| ReadIdentityFileFailed(name.into(), Box::new(e)))?, @@ -104,7 +112,10 @@ impl Identity { }) } - fn hardware(name: &str, hsm: HardwareIdentityConfiguration) -> Result { + fn hardware( + name: &str, + hsm: HardwareIdentityConfiguration, + ) -> Result { let inner = Box::new( HardwareIdentity::new( hsm.pkcs11_lib_path, @@ -126,14 +137,16 @@ impl Identity { config: IdentityConfiguration, locations: &IdentityFileLocations, log: &Logger, - ) -> Result { + ) -> Result { if let Some(hsm) = config.hsm { - Identity::hardware(name, hsm) + Identity::hardware(name, hsm).map_err(NewIdentityError::NewHardwareIdentityFailed) } else { let (pem_content, was_encrypted) = - pem_safekeeping::load_pem(log, locations, name, &config)?; + pem_safekeeping::load_pem(log, locations, name, &config) + .map_err(NewIdentityError::LoadPemFailed)?; Identity::secp256k1(name, &pem_content, was_encrypted) .or_else(|e| Identity::basic(name, &pem_content, was_encrypted).map_err(|_| e)) + .map_err(NewIdentityError::LoadPemIdentityFailed) } } diff --git a/src/dfx-core/src/identity/pem_safekeeping.rs b/src/dfx-core/src/identity/pem_safekeeping.rs index a3103ee4ad..ca520114a5 100644 --- a/src/dfx-core/src/identity/pem_safekeeping.rs +++ b/src/dfx-core/src/identity/pem_safekeeping.rs @@ -3,6 +3,12 @@ use super::IdentityConfiguration; use crate::error::encryption::EncryptionError; use crate::error::encryption::EncryptionError::{DecryptContentFailed, HashPasswordFailed}; use crate::error::fs::FsError; +use crate::error::identity::load_pem::LoadPemError; +use crate::error::identity::load_pem::LoadPemError::LoadFromKeyringFailed; +use crate::error::identity::load_pem_from_file::LoadPemFromFileError; +use crate::error::identity::load_pem_from_file::LoadPemFromFileError::{ + DecryptPemFileFailed, ReadPemFileFailed, +}; use crate::error::identity::save_pem::SavePemError; use crate::error::identity::save_pem::SavePemError::{ CannotSavePemContentForHsm, WritePemToKeyringFailed, @@ -11,10 +17,6 @@ use crate::error::identity::write_pem_to_file::WritePemToFileError; use crate::error::identity::write_pem_to_file::WritePemToFileError::{ EncryptPemFileFailed, WritePemContentFailed, }; -use crate::error::identity::IdentityError; -use crate::error::identity::IdentityError::{ - DecryptPemFileFailed, LoadPemFromKeyringFailed, ReadPemFileFailed, -}; use crate::identity::identity_file_locations::IdentityFileLocations; use crate::identity::keyring_mock; use crate::identity::pem_safekeeping::PromptMode::{DecryptingToUse, EncryptingToCreate}; @@ -30,7 +32,7 @@ pub(crate) fn load_pem( locations: &IdentityFileLocations, identity_name: &str, identity_config: &IdentityConfiguration, -) -> Result<(Vec, bool), IdentityError> { +) -> Result<(Vec, bool), LoadPemError> { if identity_config.hsm.is_some() { unreachable!("Cannot load pem content for an HSM identity.") } else if identity_config.keyring_identity_suffix.is_some() { @@ -39,11 +41,12 @@ pub(crate) fn load_pem( "Found keyring identity suffix - PEM file is stored in keyring." ); let pem = keyring_mock::load_pem_from_keyring(identity_name) - .map_err(|err| LoadPemFromKeyringFailed(Box::new(identity_name.to_string()), err))?; + .map_err(|err| LoadFromKeyringFailed(Box::new(identity_name.to_string()), err))?; Ok((pem, true)) } else { let pem_path = locations.get_identity_pem_path(identity_name, identity_config); load_pem_from_file(&pem_path, Some(identity_config)) + .map_err(LoadPemError::LoadFromFileFailed) } } @@ -80,7 +83,7 @@ pub(crate) fn save_pem( pub fn load_pem_from_file( path: &Path, config: Option<&IdentityConfiguration>, -) -> Result<(Vec, bool), IdentityError> { +) -> Result<(Vec, bool), LoadPemFromFileError> { let content = crate::fs::read(path).map_err(ReadPemFileFailed)?; let (content, was_encrypted) = maybe_decrypt_pem(content.as_slice(), config) diff --git a/src/dfx/src/commands/canister/create.rs b/src/dfx/src/commands/canister/create.rs index 84df896632..ee152f6aac 100644 --- a/src/dfx/src/commands/canister/create.rs +++ b/src/dfx/src/commands/canister/create.rs @@ -15,7 +15,7 @@ use anyhow::{bail, Context}; use byte_unit::Byte; use candid::Principal as CanisterId; use clap::{ArgAction, Parser}; -use dfx_core::error::identity::IdentityError::GetIdentityPrincipalFailed; +use dfx_core::error::identity::instantiate_identity_from_name::InstantiateIdentityFromNameError::GetIdentityPrincipalFailed; use dfx_core::identity::CallSender; use ic_agent::Identity as _; use slog::info; diff --git a/src/dfx/src/commands/canister/update_settings.rs b/src/dfx/src/commands/canister/update_settings.rs index 58d5a1d43d..b19f846991 100644 --- a/src/dfx/src/commands/canister/update_settings.rs +++ b/src/dfx/src/commands/canister/update_settings.rs @@ -14,7 +14,7 @@ use byte_unit::Byte; use candid::Principal as CanisterId; use clap::{ArgAction, Parser}; use dfx_core::cli::ask_for_consent; -use dfx_core::error::identity::IdentityError::GetIdentityPrincipalFailed; +use dfx_core::error::identity::instantiate_identity_from_name::InstantiateIdentityFromNameError::GetIdentityPrincipalFailed; use dfx_core::identity::CallSender; use fn_error_context::context; use ic_agent::identity::Identity;