From c05f22a0d31f069f7993f20496e1c42c9be550f7 Mon Sep 17 00:00:00 2001 From: lizhenglei <127465317+jackyyyyyssss@users.noreply.github.com> Date: Mon, 24 Jun 2024 15:42:20 +0800 Subject: [PATCH] fix(json): JSON.ARRTRIM key no exists (#2374) --- src/commands/cmd_json.cc | 3 +-- tests/gocase/unit/type/json/json_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc index 8f788953814..7708d2f8785 100644 --- a/src/commands/cmd_json.cc +++ b/src/commands/cmd_json.cc @@ -423,8 +423,7 @@ class CommandJsonArrTrim : public Commander { auto s = json.ArrTrim(args_[1], path_, start_, stop_, &results); if (s.IsNotFound()) { - *output = conn->NilString(); - return Status::OK(); + return {Status::RedisExecErr, "could not perform this operation on a key that doesn't exist"}; } if (!s.ok()) return {Status::RedisExecErr, s.ToString()}; diff --git a/tests/gocase/unit/type/json/json_test.go b/tests/gocase/unit/type/json/json_test.go index 8182db02df5..e720c89be4d 100644 --- a/tests/gocase/unit/type/json/json_test.go +++ b/tests/gocase/unit/type/json/json_test.go @@ -356,7 +356,7 @@ func TestJson(t *testing.T) { t.Run("JSON.ARRTRIM basics", func(t *testing.T) { require.NoError(t, rdb.Del(ctx, "a").Err()) // key no exists - require.EqualError(t, rdb.Do(ctx, "JSON.ARRTRIM", "not_exists", "$", 0, 0).Err(), redis.Nil.Error()) + require.ErrorContains(t, rdb.Do(ctx, "JSON.ARRTRIM", "not_exists", "$", 0, 0).Err(), "could not perform this operation on a key that doesn't exist") // key not json require.NoError(t, rdb.Do(ctx, "SET", "no_json", "1").Err()) require.Error(t, rdb.Do(ctx, "JSON.ARRTRIM", "no_json", "$", 0, 0).Err())