Skip to content

Commit

Permalink
binding/lua: Correct error message return
Browse files Browse the repository at this point in the history
Incorrect logic could return error message indicating wrong
function caused error.
  • Loading branch information
chu11 committed Oct 23, 2018
1 parent c7a7c12 commit 95ddec3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/bindings/lua/kvs-lua.c
Expand Up @@ -232,27 +232,35 @@ static int l_kvsdir_watch (lua_State *L)
char *key;
char *json_str = NULL;
flux_kvsdir_t *dir;
int rv = -1;

dir = lua_get_kvsdir (L, 1);
h = flux_kvsdir_handle (dir);
key = flux_kvsdir_key_at (dir, lua_tostring (L, 2));

if (lua_isnoneornil (L, 3)) {
/* Need to fetch initial value */
if (((rc = flux_kvs_get (h, key, &json_str)) < 0) && (errno != ENOENT))
if (((rc = flux_kvs_get (h, key, &json_str)) < 0)
&& (errno != ENOENT)) {
rv = lua_pusherror (L, "flux_kvs_get: %s",
(char *)flux_strerror (errno));
goto err;
}
}
else {
/* Otherwise, the value at top of stack is initial json_object */
lua_value_to_json_string (L, -1, &json_str);
}

rc = flux_kvs_watch_once (h, key, &json_str);
if ((rc = flux_kvs_watch_once (h, key, &json_str)) < 0) {
rv = lua_pusherror (L, "flux_kvs_watch_once: %s",
(char *)flux_strerror (errno));
goto err;
}
err:
free (key);
if (rc < 0)
return lua_pusherror (L, "flux_kvs_watch: %s",
(char *)flux_strerror (errno));
return rv;

json_object_string_to_lua (L, json_str);
free (json_str);
Expand Down

0 comments on commit 95ddec3

Please sign in to comment.