Skip to content

Conversation

@dragneelfps
Copy link
Contributor

Instead of panic in few commands, we can return an error to avoid unexpected panics in application code.

Resolves #2834

Instead of panic in few commands, we can return an error to avoid unexpected panics in application code.
@jit-ci
Copy link

jit-ci bot commented Oct 26, 2025

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@dragneelfps
Copy link
Contributor Author

There is also ClientSetInfo command, but I was not sure if returning a error instead will mess up existing app logic using the pipelines. Happy to to take discuss on how to handle it.

@ndyakov
Copy link
Member

ndyakov commented Oct 27, 2025

Hello @dragneelfps and thank you for your contribution! This was on our calendar for a while, glad you were able to address it. As for ClientSetInfo, this is validating the input of the command, and since this command is used when initialising the connection, if the info is not correct, the developer should fix it in the application. In my mind the initialisation of the client is the only place where panic makes sense and this is part of it. What do you think?

@dragneelfps
Copy link
Contributor Author

dragneelfps commented Oct 27, 2025

@ndyakov Honestly, I would prefer if go-redis can avoid panics altogether. Most clients usages don't handle panic well in my experience. Also, client initialization doesn't always need to be done in the initial app startup. For example, there could be scenarios where client is initialized dynamically(maybe on API request in case of server). There most servers don't expect and handle panics. Moreover, the ClientSetInfo already returns a response(StatusCmd) which can embed errors and I would assume the users will expect error there only, not a panic in case they provided invalid configuration or something.

In short, as a user of the library, I would prefer an error in the response, instead of panic even for ClientSetInfo.

By the way, this PR doesn't include any changes to ClientSetInfo so we can further discuss on it separately and have a future PR handle it. What do you think?

@ndyakov
Copy link
Member

ndyakov commented Oct 28, 2025

@dragneelfps yes, let's merge this PR and we can continue a discussion in an issue, feel free to open one.

Copy link
Member

@ndyakov ndyakov left a comment

Choose a reason for hiding this comment

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

looks good to me, commands should not panic

@ndyakov ndyakov added the bug label Oct 28, 2025
@ndyakov ndyakov merged commit 7be00c8 into redis:master Oct 28, 2025
23 checks passed
pvragov pushed a commit to pvragov/go-redis that referenced this pull request Oct 29, 2025
Instead of panic in few commands, we can return an error to avoid unexpected panics in application code.
pvragov pushed a commit to pvragov/go-redis that referenced this pull request Oct 29, 2025
Instead of panic in few commands, we can return an error to avoid unexpected panics in application code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid using panic in Redis Commands

2 participants