Skip to content

Conversation

@SaathwikDasari
Copy link

What is changed and how it works?

Replaced a panic-inducing .unwrap() on resp.leader with ok_or_else in src/pd/cluster.rs.

If resp.leader is None, the client will now return a proper error instead of crashing the entire application.

Issue reference

Closes #504

Check List

  • Code is formatted (ran cargo fmt? If not, run it locally now!)
  • This PR is signed-off

@ti-chi-bot ti-chi-bot bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Dec 30, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Dec 30, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign pingyu for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added contribution This PR is from a community contributor. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. labels Dec 30, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Dec 30, 2025

Welcome @SaathwikDasari!

It looks like this is your first PR to tikv/client-rust 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to tikv/client-rust. 😃

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a critical panic issue in the TiKV client library where calling .unwrap() on resp.leader caused application crashes when the leader was None. The fix replaces the panic-inducing unwrap with proper error handling using ok_or_else.

Key changes:

  • Replaced .unwrap() with .ok_or_else() to return a proper error instead of panicking
  • Added descriptive error message "no leader found in GetMembersResponse"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 323 to 324
.ok_or_else(|| internal_err!("no leader found in GetMembersResponse"))?;

Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace at the end of this line. Please remove it to maintain code cleanliness.

Suggested change
.ok_or_else(|| internal_err!("no leader found in GetMembersResponse"))?;
.ok_or_else(|| internal_err!("no leader found in GetMembersResponse"))?;

Copilot uses AI. Check for mistakes.
Comment on lines 323 to 324
.ok_or_else(|| internal_err!("no leader found in GetMembersResponse"))?;

Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

This empty line appears to contain trailing whitespace and should be removed. The blank line between the error handling and the for loop is not necessary and adds unnecessary whitespace.

Suggested change
.ok_or_else(|| internal_err!("no leader found in GetMembersResponse"))?;
.ok_or_else(|| internal_err!("no leader found in GetMembersResponse"))?;

Copilot uses AI. Check for mistakes.
@pingyu
Copy link
Collaborator

pingyu commented Jan 2, 2026

The resp.leader must not be None. Otherwise, Connection::try_connect (and Connection::connect) will return error (see #452).

But I think it's still nice to have this change to make it more robust.

@SaathwikDasari Please fix the error of "CI / check". Rest LGTM.

@ti-chi-bot ti-chi-bot bot added dco-signoff: no Indicates the PR's author has not signed dco. and removed dco-signoff: yes Indicates the PR's author has signed the dco. labels Jan 2, 2026
Signed-off-by: Saathwik Dasari <saathwik.dasari@gmail.com>
Signed-off-by: Saathwik Dasari <saathwik.dasari@gmail.com>
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option::unwrap() on a None` value /src/pd/cluster.rs:243:56: & 0.3.0/src/transaction/transaction.rs:1017:21:

2 participants