Skip to content

Commit 699eb0c

Browse files
committed
fixed invalid model get reponse
1 parent 247c4e5 commit 699eb0c

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/command_parser.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ static int _ModelRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **a
3030
size_t argpos = 1;
3131
RedisModuleKey *modelKey;
3232
const int status =
33-
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ);
33+
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ, error);
3434
if (status == REDISMODULE_ERR) {
35-
RAI_SetError(error, RAI_EMODELRUN, "ERR Model not found");
3635
return REDISMODULE_ERR;
3736
}
3837
RAI_HoldString(NULL, argv[argpos]);

src/model.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@
2020
#include "util/string_utils.h"
2121
#include <pthread.h>
2222
#include "DAG/dag.h"
23+
#include "err.h"
2324

2425
/* Return REDISMODULE_ERR if there was an error getting the Model.
2526
* Return REDISMODULE_OK if the model value stored at key was correctly
2627
* returned and available at *model variable. */
2728
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
28-
RAI_Model **model, int mode) {
29+
RAI_Model **model, int mode, RAI_Error *error) {
2930
*key = RedisModule_OpenKey(ctx, keyName, mode);
3031
if (RedisModule_KeyType(*key) == REDISMODULE_KEYTYPE_EMPTY) {
3132
RedisModule_CloseKey(*key);
32-
RedisModule_ReplyWithError(ctx, "ERR model key is empty");
33+
RAI_SetError(error, REDISMODULE_KEYTYPE_EMPTY, "ERR model key is empty");
3334
return REDISMODULE_ERR;
3435
}
3536
if (RedisModule_ModuleTypeGetType(*key) != RedisAI_ModelType) {
3637
RedisModule_CloseKey(*key);
37-
RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
38+
RAI_SetError(error, REDISMODULE_ERR, REDISMODULE_ERRORMSG_WRONGTYPE);
3839
return REDISMODULE_ERR;
3940
}
4041
*model = RedisModule_ModuleTypeGetValue(*key);

src/model.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ int RAI_ModelSerialize(RAI_Model *model, char **buffer, size_t *len, RAI_Error *
116116
* a Redis key with the requested access mode
117117
* @param model destination model structure
118118
* @param mode key access mode
119+
* @param error contains the error in case of problem with retrival
119120
* @return REDISMODULE_OK if the model value stored at key was correctly
120121
* returned and available at *model variable, or REDISMODULE_ERR if there was
121122
* an error getting the Model
122123
*/
123124
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
124-
RAI_Model **model, int mode);
125+
RAI_Model **model, int mode, RAI_Error *error);
125126

126127
/**
127128
* When a module command is called in order to obtain the position of

src/redisai.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,11 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
414414

415415
RAI_Model *mto;
416416
RedisModuleKey *key;
417-
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ);
417+
RAI_Error err = {0};
418+
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ, &err);
418419
if (status == REDISMODULE_ERR) {
420+
RedisModule_ReplyWithError(ctx, err.detail);
421+
RAI_ClearError(&err);
419422
return REDISMODULE_ERR;
420423
}
421424

@@ -434,7 +437,6 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
434437
return RedisModule_ReplyWithError(ctx, "ERR no META or BLOB specified");
435438
}
436439

437-
RAI_Error err = {0};
438440
char *buffer = NULL;
439441
size_t len = 0;
440442

@@ -512,11 +514,14 @@ int RedisAI_ModelDel_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
512514
if (argc != 2)
513515
return RedisModule_WrongArity(ctx);
514516

517+
RAI_Error err = {0};
515518
RAI_Model *mto;
516519
RedisModuleKey *key;
517-
const int status =
518-
RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ | REDISMODULE_WRITE);
520+
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto,
521+
REDISMODULE_READ | REDISMODULE_WRITE, &err);
519522
if (status == REDISMODULE_ERR) {
523+
RedisModule_ReplyWithError(ctx, err.detail);
524+
RAI_ClearError(&err);
520525
return REDISMODULE_ERR;
521526
}
522527

0 commit comments

Comments
 (0)