@@ -54,10 +54,8 @@ static void _DAGFinishFunc(RAI_OnFinishCtx *onFinishCtx, void *private_data) {
5454
5555 RAI_RunResults * results = (RAI_RunResults * )private_data ;
5656 if (RedisAI_DAGRunError (onFinishCtx )) {
57- for (size_t i = 0 ; i < RedisAI_DAGNumOps (onFinishCtx ); i ++ ) {
58- RAI_Error * error = RedisAI_DAGGetError (onFinishCtx );
59- RedisAI_SetError (results -> error , RedisAI_GetErrorCode (error ), RedisAI_GetError (error ));
60- }
57+ const RAI_Error * error = RedisAI_DAGGetError (onFinishCtx );
58+ RedisAI_CloneError (results -> error , error );
6159 pthread_cond_signal (& global_cond );
6260 return ;
6361 }
@@ -74,10 +72,12 @@ static void _DAGFinishFunc(RAI_OnFinishCtx *onFinishCtx, void *private_data) {
7472 pthread_cond_signal (& global_cond );
7573}
7674
77- int testModelRunOpError (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
75+ int testModelRunOpError (RedisModuleCtx * ctx ) {
7876
77+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
7978 RAI_Error * err ;
8079 RedisAI_InitError (& err );
80+ int res = LLAPIMODULE_ERR ;
8181 // The model m{1} should exist in key space.
8282 RAI_Model * model = (RAI_Model * )_getFromKeySpace (ctx , "m{1}" );
8383 RAI_DAGRunOp * op = RedisAI_DAGCreateModelRunOp (model );
@@ -86,25 +86,28 @@ int testModelRunOpError(RedisModuleCtx *ctx, RAI_DAGRunCtx *run_info) {
8686 // This model expect for 2 inputs not 1.
8787 int status = RedisAI_DAGAddRunOp (run_info , op , err );
8888 if (!_assertError (err , status , "Number of keys given as INPUTS does not match model definition" )) {
89- RedisAI_FreeError (err );
90- return LLAPIMODULE_ERR ;
89+ goto cleanup ;
9190 }
9291 RedisAI_ClearError (err );
9392 RedisAI_DAGRunOpAddInput (op , "second_input" );
9493 status = RedisAI_DAGAddRunOp (run_info , op , err );
9594
9695 // We still get an error since the model expects for an output as well.
9796 if (!_assertError (err , status , "Number of keys given as OUTPUTS does not match model definition" )) {
98- RedisAI_FreeError (err );
99- return LLAPIMODULE_ERR ;
97+ goto cleanup ;
10098 }
99+ res = LLAPIMODULE_OK ;
100+
101+ cleanup :
101102 RedisAI_FreeError (err );
102103 RedisAI_DAGRunOpFree (op );
103- return LLAPIMODULE_OK ;
104+ RedisAI_DAGFree (run_info );
105+ return res ;
104106}
105107
106- int testEmptyDAGError (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
108+ int testEmptyDAGError (RedisModuleCtx * ctx ) {
107109
110+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
108111 RAI_Error * err ;
109112 RedisAI_InitError (& err );
110113 int res = LLAPIMODULE_ERR ;
@@ -124,8 +127,9 @@ int testEmptyDAGError(RedisModuleCtx *ctx, RAI_DAGRunCtx *run_info) {
124127 return res ;
125128}
126129
127- int testKeysMismatchError (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
130+ int testKeysMismatchError (RedisModuleCtx * ctx ) {
128131
132+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
129133 RAI_Error * err ;
130134 RedisAI_InitError (& err );
131135 int res = LLAPIMODULE_ERR ;
@@ -146,8 +150,9 @@ int testKeysMismatchError(RedisModuleCtx *ctx,RAI_DAGRunCtx *run_info) {
146150 return res ;
147151}
148152
149- int testBuildDAGFromString (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
153+ int testBuildDAGFromString (RedisModuleCtx * ctx ) {
150154
155+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
151156 RAI_RunResults results ;
152157 _InitRunResults (& results );
153158 int res = LLAPIMODULE_ERR ;
@@ -200,8 +205,9 @@ int testBuildDAGFromString(RedisModuleCtx *ctx,RAI_DAGRunCtx *run_info) {
200205 return res ;
201206}
202207
203- int testSimpleDAGRun (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
208+ int testSimpleDAGRun (RedisModuleCtx * ctx ) {
204209
210+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
205211 RAI_RunResults results ;
206212 _InitRunResults (& results );
207213 int res = LLAPIMODULE_ERR ;
@@ -252,8 +258,9 @@ int testSimpleDAGRun(RedisModuleCtx *ctx, RAI_DAGRunCtx *run_info) {
252258 return res ;
253259}
254260
255- int testSimpleDAGRun2 (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
261+ int testSimpleDAGRun2 (RedisModuleCtx * ctx ) {
256262
263+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
257264 RAI_RunResults results ;
258265 _InitRunResults (& results );
259266 int res = LLAPIMODULE_ERR ;
@@ -304,8 +311,9 @@ int testSimpleDAGRun2(RedisModuleCtx *ctx, RAI_DAGRunCtx *run_info) {
304311 return res ;
305312}
306313
307- int testSimpleDAGRun2Error (RedisModuleCtx * ctx , RAI_DAGRunCtx * run_info ) {
314+ int testSimpleDAGRun2Error (RedisModuleCtx * ctx ) {
308315
316+ RAI_DAGRunCtx * run_info = RedisAI_DAGRunCtxCreate ();
309317 RAI_RunResults results ;
310318 _InitRunResults (& results );
311319 int res = LLAPIMODULE_ERR ;
0 commit comments