Skip to content

Commit 5f785de

Browse files
authored
Fix empty err msg (#132)
* Emit specific errors when key is empty * Emit specific errors when key is empty in run commands
1 parent 17b47b5 commit 5f785de

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/redisai.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,12 @@ int RedisAI_ModelRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
705705
AC_GetRString(&ac, &keystr, 0);
706706

707707
RedisModuleKey *key = RedisModule_OpenKey(ctx, keystr, REDISMODULE_READ);
708-
if (!(RedisModule_KeyType(key) == REDISMODULE_KEYTYPE_MODULE &&
708+
int type = RedisModule_KeyType(key);
709+
if (type == REDISMODULE_KEYTYPE_EMPTY) {
710+
RedisModule_CloseKey(key);
711+
return RedisModule_ReplyWithError(ctx, "ERR model key is empty");
712+
}
713+
if (!(type == REDISMODULE_KEYTYPE_MODULE &&
709714
RedisModule_ModuleTypeGetType(key) == RedisAI_ModelType)) {
710715
RedisModule_CloseKey(key);
711716
return RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
@@ -756,9 +761,15 @@ int RedisAI_ModelRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
756761

757762
for (size_t i=0; i<ninputs; i++) {
758763
RedisModuleKey *argkey = RedisModule_OpenKey(ctx, inputs[i], REDISMODULE_READ);
764+
int type = RedisModule_KeyType(argkey);
765+
if (type == REDISMODULE_KEYTYPE_EMPTY) {
766+
// todo free rinfo, close key
767+
RedisModule_CloseKey(argkey);
768+
return RedisModule_ReplyWithError(ctx, "Input key is empty");
769+
}
759770
if (!(RedisModule_KeyType(argkey) == REDISMODULE_KEYTYPE_MODULE &&
760771
RedisModule_ModuleTypeGetType(argkey) == RedisAI_TensorType)) {
761-
// todo free rinfo
772+
// todo free rinfo, close key
762773
RedisModule_CloseKey(argkey);
763774
return RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
764775
}
@@ -857,7 +868,12 @@ int RedisAI_ScriptRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
857868
// - A: a separate thread and queue for scripts
858869
// - B: the same thread and queue for models and scripts
859870
RedisModuleKey *key = RedisModule_OpenKey(ctx, keystr, REDISMODULE_READ);
860-
if (!(RedisModule_KeyType(key) == REDISMODULE_KEYTYPE_MODULE &&
871+
int type = RedisModule_KeyType(key);
872+
if (type == REDISMODULE_KEYTYPE_EMPTY) {
873+
RedisModule_CloseKey(key);
874+
return RedisModule_ReplyWithError(ctx, "ERR script key is empty");
875+
}
876+
if (!(type == REDISMODULE_KEYTYPE_MODULE &&
861877
RedisModule_ModuleTypeGetType(key) == RedisAI_ScriptType)) {
862878
RedisModule_CloseKey(key);
863879
return RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
@@ -902,7 +918,12 @@ int RedisAI_ScriptRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
902918

903919
for (size_t i=0; i<ninputs; i++) {
904920
RedisModuleKey *argkey = RedisModule_OpenKey(ctx, inputs[i], REDISMODULE_READ);
905-
if (!(RedisModule_KeyType(argkey) == REDISMODULE_KEYTYPE_MODULE &&
921+
int type = RedisModule_KeyType(argkey);
922+
if (type == REDISMODULE_KEYTYPE_EMPTY) {
923+
RedisModule_CloseKey(argkey);
924+
return RedisModule_ReplyWithError(ctx, "Input key is empty");
925+
}
926+
if (!(type == REDISMODULE_KEYTYPE_MODULE &&
906927
RedisModule_ModuleTypeGetType(argkey) == RedisAI_TensorType)) {
907928
RedisModule_CloseKey(argkey);
908929
return RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);

0 commit comments

Comments
 (0)