Skip to content

refactor(clippy): do not panic in production code paths#178

Merged
AlfioEmanueleFresta merged 9 commits intomasterfrom
nopanic
Mar 4, 2026
Merged

refactor(clippy): do not panic in production code paths#178
AlfioEmanueleFresta merged 9 commits intomasterfrom
nopanic

Conversation

@AlfioEmanueleFresta
Copy link
Member

@AlfioEmanueleFresta AlfioEmanueleFresta commented Mar 3, 2026

  • Remove all unwrap, todo, expect, unreachable from non-test code paths
  • Add strict no-panic clippy checks for the future

Makes the code a bit more verbose, but safer from (future) panics.


impl fmt::Display for Channel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
let card = self.card.lock().unwrap();
Copy link
Member Author

Choose a reason for hiding this comment

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

The previous Display for pcsc Channel acquired the mutex and called
Card::status2() at display time, then collected CardStatus::reader_names().

Per the PC/SC spec, SCardStatus returns "the names by which the connected card reader is known"

  • i.e. the same reader the handle was opened with via
    Context::connect().
    Since the reader name is fixed for the lifetime of the card handle, we now capture it from Info
    at construction time, avoiding the mutex lock and potential SCardStatus failures in Display.

@AlfioEmanueleFresta AlfioEmanueleFresta changed the title clean(clippy): do not panic in production code paths refactor(clippy): do not panic in production code paths Mar 4, 2026
@AlfioEmanueleFresta AlfioEmanueleFresta added the enhancement New feature or request label Mar 4, 2026
Copy link
Collaborator

@msirringhaus msirringhaus left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

Base automatically changed from issue-142 to master March 4, 2026 18:27
@AlfioEmanueleFresta AlfioEmanueleFresta merged commit 5df814b into master Mar 4, 2026
4 checks passed
@AlfioEmanueleFresta AlfioEmanueleFresta deleted the nopanic branch March 4, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants