Skip to content

Commit 007505e

Browse files
BorysTheDevromange
andauthored
fix: script error reply (#5776)
* fix: script error reply Co-authored-by: Roman Gershman <[email protected]>
1 parent 78f24b7 commit 007505e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/server/dragonfly_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ TEST_F(SingleThreadDflyEngineTest, GlobalSingleThread) {
149149
Run({"move", "a", "1"});
150150
}
151151

152+
TEST_F(DflyEngineTest, LuaErrors) {
153+
auto resp = Run({"eval", "return redis.error_reply('some error')", "0"});
154+
EXPECT_THAT(resp, ErrArg("some error"));
155+
156+
resp = Run({"eval", "return redis.pcall('foo', 'bar')", "0"});
157+
EXPECT_THAT(resp, ErrArg("ERR unknown command"));
158+
159+
resp = Run({"eval", "return redis.pcall('incrby', 'foo', 'bar')", "1"});
160+
EXPECT_THAT(resp, ErrArg("ERR Number of keys can't be greater than number of args"));
161+
}
162+
152163
TEST_F(DflyEngineTest, EvalResp) {
153164
auto resp = Run({"eval", "return 43", "0"});
154165
EXPECT_THAT(resp, IntArg(43));

src/server/main_service.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ class EvalSerializer : public ObjectExplorer {
383383
}
384384

385385
void OnError(string_view str) {
386-
rb_->SendError(str);
386+
if (!str.empty() && str.front() != '-') {
387+
rb_->SendError(absl::StrCat("-", str));
388+
} else {
389+
rb_->SendError(str);
390+
}
387391
}
388392

389393
private:
@@ -411,7 +415,11 @@ void InterpreterReplier::PostItem() {
411415
void InterpreterReplier::SendError(string_view str, std::string_view type) {
412416
DCHECK(array_len_.empty());
413417
DVLOG(1) << "Lua/df_call error " << str;
414-
explr_->OnError(str);
418+
if (!str.empty() && str.front() != '-') {
419+
explr_->OnError(absl::StrCat("-ERR ", str));
420+
} else {
421+
explr_->OnError(str);
422+
}
415423
}
416424

417425
void InterpreterReplier::SendSimpleString(string_view str) {

0 commit comments

Comments
 (0)