Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrongly append the ERR prefix in no script error #1162

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/commands/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const char *errLimitOptionNotAllowed = "syntax error, LIMIT cannot be used witho
const char *errZSetLTGTNX = "GT, LT, and/or NX options at the same time are not compatible";
const char *errScoreIsNotValidFloat = "score is not a valid float";
const char *errValueIsNotFloat = "value is not a valid float";
const char *errNoMatchingScript = "NOSCRIPT No matching script. Please use EVAL";

enum class AuthResult {
OK,
Expand Down Expand Up @@ -5311,14 +5312,11 @@ class CommandEval : public Commander {

class CommandEvalSHA : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
if (args[1].size() != 40) {
return {Status::NotOK, "NOSCRIPT No matching script. Please use EVAL"};
}
return Status::OK();
}

Status Execute(Server *svr, Connection *conn, std::string *output) override {
if (args_[1].size() != 40) {
*output = Redis::Error(errNoMatchingScript);
return Status::OK();
}
return Lua::evalGenericCommand(conn, args_, true, output);
}
};
Expand All @@ -5332,14 +5330,11 @@ class CommandEvalRO : public Commander {

class CommandEvalSHARO : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
if (args[1].size() != 40) {
return {Status::NotOK, "NOSCRIPT No matching script. Please use EVAL"};
}
return Status::OK();
}

Status Execute(Server *svr, Connection *conn, std::string *output) override {
if (args_[1].size() != 40) {
*output = Redis::Error(errNoMatchingScript);
return Status::OK();
}
return Lua::evalGenericCommand(conn, args_, true, output, true);
}
};
Expand Down
6 changes: 3 additions & 3 deletions tests/gocase/unit/scripting/scripting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ func TestScripting(t *testing.T) {

t.Run("EVALSHA - Do we get an error on invalid SHA1?", func(t *testing.T) {
r := rdb.EvalSha(ctx, "NotValidShaSUM", []string{})
util.ErrorRegexp(t, r.Err(), "ERR NOSCRIPT.*")
util.ErrorRegexp(t, r.Err(), "NOSCRIPT.*")
require.Nil(t, r.Val())
})

t.Run("EVALSHA - Do we get an error on non defined SHA1?", func(t *testing.T) {
r := rdb.EvalSha(ctx, "ffd632c7d33e571e9f24556ebed26c3479a87130", []string{})
util.ErrorRegexp(t, r.Err(), "ERR NOSCRIPT.*")
util.ErrorRegexp(t, r.Err(), "NOSCRIPT.*")
require.Nil(t, r.Val())
})

Expand Down Expand Up @@ -354,7 +354,7 @@ assert(bit.bor(1,2,4,8,16,32,64,128) == 255)
require.Equal(t, "myval", r.Val())
require.NoError(t, rdb.ScriptFlush(ctx).Err())
r = rdb.EvalSha(ctx, "fd758d1589d044dd850a6f05d52f2eefd27f033f", []string{"mykey"})
util.ErrorRegexp(t, r.Err(), "ERR NOSCRIPT.*")
util.ErrorRegexp(t, r.Err(), "NOSCRIPT.*")
})

t.Run("SCRIPT EXISTS - can detect already defined scripts?", func(t *testing.T) {
Expand Down