Skip to content

Commit

Permalink
Fix wrongly append the ERR prefix in no script error (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk authored Dec 6, 2022
1 parent f7638e6 commit 9e4bb2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
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

0 comments on commit 9e4bb2c

Please sign in to comment.