Skip to content

fix(common): errors with clippy pedantic (manual_assert)#3204

Open
chammika wants to merge 3 commits intoapache:masterfrom
chammika:fix/clippy-pedantic
Open

fix(common): errors with clippy pedantic (manual_assert)#3204
chammika wants to merge 3 commits intoapache:masterfrom
chammika:fix/clippy-pedantic

Conversation

@chammika
Copy link
Copy Markdown

@chammika chammika commented May 1, 2026

Which issue does this PR close?

This PR fixes some issues raised by clippy pedantic mode

cargo clippy -- -W clippy::manual_assert

Closes #3205

Rationale

This was suggested by Clippy as better practice

https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#manual_assert

What changed?

Fix all clippy::manual_assert cases indicated by clippy

Local Execution

  • Passed
  • Pre-commit hooks ran

AI Usage

None

cargo clippy -- -W clippy::manual_assert
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 70.37037% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.51%. Comparing base (f02a43a) to head (954f8a0).

Files with missing lines Patch % Lines
...ore/common/src/types/message/messages_batch_mut.rs 0.00% 3 Missing ⚠️
core/common/src/types/message/messages_batch.rs 0.00% 2 Missing ⚠️
...ore/common/src/types/message/messages_batch_set.rs 0.00% 2 Missing ⚠️
core/server/src/bootstrap.rs 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3204      +/-   ##
============================================
- Coverage     74.09%   71.51%   -2.59%     
  Complexity      943      943              
============================================
  Files          1164     1164              
  Lines        103048    98355    -4693     
  Branches      80083    75405    -4678     
============================================
- Hits          76353    70337    -6016     
- Misses        24006    25137    +1131     
- Partials       2689     2881     +192     
Components Coverage Δ
Rust Core 71.99% <70.37%> (-3.33%) ⬇️
Java SDK 60.14% <ø> (ø)
C# SDK 69.07% <ø> (-0.31%) ⬇️
Python SDK 81.43% <ø> (ø)
Node SDK 91.53% <ø> (+0.13%) ⬆️
Go SDK 39.60% <ø> (ø)
Files with missing lines Coverage Δ
core/common/src/utils/versioning.rs 80.16% <100.00%> (+0.49%) ⬆️
core/server/src/http/http_server.rs 48.80% <100.00%> (+0.19%) ⬆️
core/server/src/bootstrap.rs 81.98% <91.66%> (+1.12%) ⬆️
core/common/src/types/message/messages_batch.rs 68.20% <0.00%> (+0.39%) ⬆️
...ore/common/src/types/message/messages_batch_set.rs 72.46% <0.00%> (+0.34%) ⬆️
...ore/common/src/types/message/messages_batch_mut.rs 49.79% <0.00%> (+0.10%) ⬆️

... and 116 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chammika chammika marked this pull request as ready for review May 1, 2026 10:41
@chammika chammika changed the title fix: errors with clippy pedantic (manual_assert) fix(common): errors with clippy pedantic (manual_assert) May 1, 2026
if bytes.is_empty() {
panic!("Can not parse empty string as u32");
}
assert!(!bytes.is_empty(), "End index out of bounds");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message "End index out of bounds" doesn't describe the !bytes.is_empty() check - it describes a different condition (matching the assertion at line 96 about end <= bytes.len()). this is a diagnostic regression: original message was "Can not parse empty string as u32", which actually matched the check. restore the original message.

Comment on lines +132 to +135
assert!(
!((username.is_ok() && password.is_err()) || (username.is_err() && password.is_ok())),
"When providing the custom root user credentials, both username and password must be set."
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double-negated XOR is hard to parse. equivalent and clearer:

assert_eq!(
    username.is_ok(),
    password.is_ok(),
    "When providing the custom root user credentials, both username and password must be set."
);

Comment on lines +313 to +316
assert!(
jwt_manager.load_revoked_tokens().await.is_ok(),
"Failed to load revoked access tokens"
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert!(... .is_ok(), "...") drops the underlying error from load_revoked_tokens(). the original if .is_err() { panic!(...) } had the same issue, so this isn't a regression from this PR, but worth fixing while you're in here:

if let Err(error) = jwt_manager.load_revoked_tokens().await {
    panic!("Failed to load revoked access tokens: {error}");
}

Copy link
Copy Markdown
Contributor

@Standing-Man Standing-Man left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing panic with assert in many places is not appropriate. It would be better to return proper error types with clear error messages, rather than using assert to validate configuration. cc @hubcio WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix some clippy warnings

3 participants