This is an automated email from the ASF dual-hosted git repository.
hgruszecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git
The following commit(s) were added to refs/heads/master by this push:
new 93be9355 feat(cli): Implement error handling for cli encryptor parsing
(#2160)
93be9355 is described below
commit 93be935506d96c28e968e21ae6d87ed6816d977f
Author: I-Hsin Cheng <[email protected]>
AuthorDate: Tue Sep 9 23:51:59 2025 +0800
feat(cli): Implement error handling for cli encryptor parsing (#2160)
In the main loop of iggy-cli, putting invalid value for encryptor will
generate a panic from client side, however, a panic should refer to a
programmer bug rather than invalid user input.
This PR fixes it.
---
core/cli/src/error.rs | 4 ++++
core/cli/src/main.rs | 14 ++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/core/cli/src/error.rs b/core/cli/src/error.rs
index 4ff38874..84a79151 100644
--- a/core/cli/src/error.rs
+++ b/core/cli/src/error.rs
@@ -22,6 +22,7 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub(crate) enum CmdToolError {
MissingCredentials,
+ InvalidEncryptionKey,
#[cfg(feature = "login-session")]
MissingServerAddress,
}
@@ -32,6 +33,9 @@ impl Display for CmdToolError {
Self::MissingCredentials => {
write!(f, "Missing iggy server credentials")
}
+ Self::InvalidEncryptionKey => {
+ write!(f, "Invalid encryption key provided")
+ }
#[cfg(feature = "login-session")]
Self::MissingServerAddress => {
write!(f, "Missing iggy server address")
diff --git a/core/cli/src/main.rs b/core/cli/src/main.rs
index 9dd22f39..d21536bb 100644
--- a/core/cli/src/main.rs
+++ b/core/cli/src/main.rs
@@ -27,7 +27,7 @@ use crate::args::{
personal_access_token::PersonalAccessTokenAction, stream::StreamAction,
topic::TopicAction,
};
use crate::credentials::IggyCredentials;
-use crate::error::IggyCmdError;
+use crate::error::{CmdToolError, IggyCmdError};
use crate::logging::Logging;
use args::context::ContextAction;
use args::message::MessageAction;
@@ -370,9 +370,15 @@ async fn main() -> Result<(), IggyCmdError> {
let encryptor = match iggy_args.encryption_key.is_empty() {
true => None,
- false => Some(Arc::new(EncryptorKind::Aes256Gcm(
-
Aes256GcmEncryptor::from_base64_key(&iggy_args.encryption_key).unwrap(),
- ))),
+ false => {
+ let encryption_key =
Aes256GcmEncryptor::from_base64_key(&iggy_args.encryption_key)
+ .map_err(|_| {
+ <IggyCmdError as
Into<anyhow::Error>>::into(IggyCmdError::CmdToolError(
+ CmdToolError::InvalidEncryptionKey,
+ ))
+ })?;
+ Some(Arc::new(EncryptorKind::Aes256Gcm(encryption_key)))
+ }
};
let client_provider_config =
Arc::new(ClientProviderConfig::from_args_set_autologin(
iggy_args.clone(),