This is an automated email from the ASF dual-hosted git repository.
hubcio 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 1e44cc5b9 fix(common): errors with clippy pedantic (manual_assert)
(#3204)
1e44cc5b9 is described below
commit 1e44cc5b965f3de4771a670e739f33ee78ea3ff2
Author: Chammika Mannakkara <[email protected]>
AuthorDate: Tue May 12 20:33:53 2026 +0900
fix(common): errors with clippy pedantic (manual_assert) (#3204)
---
core/common/src/types/message/messages_batch.rs | 12 +++---
.../common/src/types/message/messages_batch_mut.rs | 13 +++----
.../common/src/types/message/messages_batch_set.rs | 12 +++---
core/common/src/utils/versioning.rs | 23 ++++-------
core/server/src/bootstrap.rs | 45 ++++++++++++----------
core/server/src/http/http_server.rs | 4 +-
examples/rust/src/shared/codec.rs | 7 ++--
7 files changed, 57 insertions(+), 59 deletions(-)
diff --git a/core/common/src/types/message/messages_batch.rs
b/core/common/src/types/message/messages_batch.rs
index 176376d4e..f450eb3a7 100644
--- a/core/common/src/types/message/messages_batch.rs
+++ b/core/common/src/types/message/messages_batch.rs
@@ -152,12 +152,12 @@ impl Index<usize> for IggyMessagesBatch {
type Output = [u8];
fn index(&self, index: usize) -> &Self::Output {
- if index >= self.count as usize {
- panic!(
- "Index out of bounds: the len is {} but the index is {}",
- self.count, index
- );
- }
+ assert!(
+ index < self.count as usize,
+ "Index out of bounds: the len is {} but the index is {}",
+ self.count,
+ index
+ );
let (start, end) = self
.get_message_boundaries(index)
diff --git a/core/common/src/types/message/messages_batch_mut.rs
b/core/common/src/types/message/messages_batch_mut.rs
index 1b326932b..15174376a 100644
--- a/core/common/src/types/message/messages_batch_mut.rs
+++ b/core/common/src/types/message/messages_batch_mut.rs
@@ -819,13 +819,12 @@ impl Index<usize> for IggyMessagesBatchMut {
type Output = [u8];
fn index(&self, index: usize) -> &Self::Output {
- if index >= self.count() as usize {
- panic!(
- "Index out of bounds: the len is {} but the index is {}",
- self.count(),
- index
- );
- }
+ assert!(
+ index < self.count() as usize,
+ "Index out of bounds: the len is {} but the index is {}",
+ self.count(),
+ index
+ );
let (start, end) = self
.get_message_boundaries(index)
diff --git a/core/common/src/types/message/messages_batch_set.rs
b/core/common/src/types/message/messages_batch_set.rs
index 41183ae83..6751b3580 100644
--- a/core/common/src/types/message/messages_batch_set.rs
+++ b/core/common/src/types/message/messages_batch_set.rs
@@ -335,12 +335,12 @@ impl Index<usize> for IggyMessagesBatchSet {
///
/// Panics if the index is out of bounds (>= total number of messages)
fn index(&self, index: usize) -> &Self::Output {
- if index >= self.count as usize {
- panic!(
- "Index out of bounds: the len is {} but the index is {}",
- self.count, index
- );
- }
+ assert!(
+ index < self.count as usize,
+ "Index out of bounds: the len is {} but the index is {}",
+ self.count,
+ index
+ );
let mut seen_messages = 0;
diff --git a/core/common/src/utils/versioning.rs
b/core/common/src/utils/versioning.rs
index 3356b1bad..d0f688525 100644
--- a/core/common/src/utils/versioning.rs
+++ b/core/common/src/utils/versioning.rs
@@ -36,23 +36,17 @@ pub struct SemanticVersion {
/// - If the string is empty
/// - If the string contains non-digit characters
const fn const_parse_u32_range(bytes: &[u8], start: usize, end: usize) -> u32 {
- if start >= end {
- panic!("Cannot parse empty range as u32");
- }
+ assert!(start < end, "Cannot parse empty range as u32");
let mut result = 0u32;
let mut i = start;
- if bytes.is_empty() {
- panic!("Can not parse empty string as u32");
- }
+ assert!(!bytes.is_empty(), "Can not parse empty string as u32");
while i < end {
let byte = bytes[i];
- if !byte.is_ascii_digit() {
- panic!("Invalid digit in version number");
- }
+ assert!(byte.is_ascii_digit(), "Invalid digit in version number");
// ASCII '0' - '9' to 0-9
let digit = bytes[i] - b'0';
@@ -95,12 +89,11 @@ const fn find_byte_pos_or_len(bytes: &[u8], target: u8) ->
usize {
const fn const_str_slice(s: &str, start: usize, end: usize) -> &str {
let bytes = s.as_bytes();
- if start > end {
- panic!("Start index must be less than or equal to end index");
- }
- if end > bytes.len() {
- panic!("End index out of bounds");
- }
+ assert!(
+ start <= end,
+ "Start index must be less than or equal to end index"
+ );
+ assert!(end <= bytes.len(), "End index out of bounds");
// SAFETY: Creating a slice within the bound of original byte slice.
let slice = unsafe {
core::slice::from_raw_parts(bytes.as_ptr().add(start), end - start) };
diff --git a/core/server/src/bootstrap.rs b/core/server/src/bootstrap.rs
index 3a5661bce..441243246 100644
--- a/core/server/src/bootstrap.rs
+++ b/core/server/src/bootstrap.rs
@@ -129,11 +129,11 @@ pub async fn create_directories(config: &SystemConfig) ->
Result<(), IggyError>
pub fn create_root_user() -> User {
let mut username = env::var(IGGY_ROOT_USERNAME_ENV);
let mut password = env::var(IGGY_ROOT_PASSWORD_ENV);
- if (username.is_ok() && password.is_err()) || (username.is_err() &&
password.is_ok()) {
- panic!(
- "When providing the custom root user credentials, both username
and password must be set."
- );
- }
+ assert_eq!(
+ username.is_ok(),
+ password.is_ok(),
+ "When providing the custom root user credentials, both username and
password must be set."
+ );
if username.is_ok() && password.is_ok() {
info!("Using the custom root user credentials.");
} else {
@@ -146,21 +146,26 @@ pub fn create_root_user() -> User {
let username = username.expect("Root username is not set.");
let password = password.expect("Root password is not set.");
- if username.is_empty() || password.is_empty() {
- panic!("Root user credentials are not set.");
- }
- if username.len() < MIN_USERNAME_LENGTH {
- panic!("Root username is too short.");
- }
- if username.len() > MAX_USERNAME_LENGTH {
- panic!("Root username is too long.");
- }
- if password.len() < MIN_PASSWORD_LENGTH {
- panic!("Root password is too short.");
- }
- if password.len() > MAX_PASSWORD_LENGTH {
- panic!("Root password is too long.");
- }
+ assert!(
+ !username.is_empty() && !password.is_empty(),
+ "Root user credentials cannot be empty."
+ );
+ assert!(
+ username.len() >= MIN_USERNAME_LENGTH,
+ "Root username is too short."
+ );
+ assert!(
+ username.len() <= MAX_USERNAME_LENGTH,
+ "Root username is too long."
+ );
+ assert!(
+ password.len() >= MIN_PASSWORD_LENGTH,
+ "Root password is too short."
+ );
+ assert!(
+ password.len() <= MAX_PASSWORD_LENGTH,
+ "Root password is too long."
+ );
User::root(&username, &password)
}
diff --git a/core/server/src/http/http_server.rs
b/core/server/src/http/http_server.rs
index 177e4f7ef..b8e56d51a 100644
--- a/core/server/src/http/http_server.rs
+++ b/core/server/src/http/http_server.rs
@@ -310,8 +310,8 @@ async fn build_app_state(
Ok(manager) => manager,
Err(error) => panic!("Failed to initialize JWT manager: {error}"),
};
- if jwt_manager.load_revoked_tokens().await.is_err() {
- panic!("Failed to load revoked access tokens");
+ if let Err(error) = jwt_manager.load_revoked_tokens().await {
+ panic!("Failed to load revoked access tokens: {error}");
}
Arc::new(AppState {
diff --git a/examples/rust/src/shared/codec.rs
b/examples/rust/src/shared/codec.rs
index 3625be417..780595248 100644
--- a/examples/rust/src/shared/codec.rs
+++ b/examples/rust/src/shared/codec.rs
@@ -102,9 +102,10 @@ impl Codec {
.read_to_end(&mut decompressed_data)
.expect("Cannot decode payload using Lz4.");
- if bytes_read > MAX_PAYLOAD_SIZE as usize {
- panic!("Decompressed message exceeds MAX_PAYLOAD_SIZE!")
- }
+ assert!(
+ bytes_read <= MAX_PAYLOAD_SIZE as usize,
+ "Decompressed message exceeds MAX_PAYLOAD_SIZE!"
+ );
decompressed_data
}
}