]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: standardize zlog error messages
authorDonald Lee <dlqs@gmx.com>
Wed, 7 Jul 2021 18:40:18 +0000 (02:40 +0800)
committerDonald Lee <dlqs@gmx.com>
Sat, 17 Jul 2021 22:32:03 +0000 (06:32 +0800)
Signed-off-by: Donald Lee <dlqs@gmx.com>
lib/frrscript.c
lib/frrscript.h

index 9b497a431d6a27aef4a40d6fc00131ad2342ef77..8252455fd9951e2fc0acffed319926329626fd2b 100644 (file)
@@ -137,7 +137,7 @@ static void lua_function_free(struct hash_bucket *b, void *data)
        XFREE(MTYPE_SCRIPT, lfs);
 }
 
-/* Generic script APIs */
+/* internal frrscript APIs */
 
 int _frrscript_call_lua(struct lua_function_state *lfs, int nargs)
 {
@@ -214,7 +214,9 @@ void *frrscript_get_result(struct frrscript *fs, const char *function_name,
        lua_getfield(lfs->L, 1, name);
        if (lua_isnil(lfs->L, -1)) {
                lua_pop(lfs->L, 1);
-               zlog_err("No result in results table with that name %s", name);
+               zlog_warn(
+                       "frrscript: '%s.lua': '%s': tried to decode '%s' as result but failed",
+                       fs->name, function_name, name);
                return NULL;
        }
        p = lua_to(lfs->L, 2);
@@ -259,34 +261,39 @@ int frrscript_load(struct frrscript *fs, const char *function_name,
        lua_State *L = luaL_newstate();
        frrlua_export_logging(L);
 
-       char fname[MAXPATHLEN * 2];
+       char script_name[MAXPATHLEN * 2];
 
-       snprintf(fname, sizeof(fname), "%s/%s.lua", scriptdir, fs->name);
-       int ret = luaL_dofile(L, fname);
+       snprintf(script_name, sizeof(script_name), "%s/%s.lua", scriptdir,
+                fs->name);
+       int ret = luaL_dofile(L, script_name);
 
        switch (ret) {
        case LUA_OK:
                break;
        case LUA_ERRSYNTAX:
-               zlog_err("Failed loading script '%s': syntax error: %s", fname,
-                        lua_tostring(L, -1));
+               zlog_err(
+                       "frrscript: failed loading script '%s.lua': syntax error: %s",
+                       script_name, lua_tostring(L, -1));
                break;
        case LUA_ERRMEM:
-               zlog_err("Failed loading script '%s': out-of-memory error: %s",
-                        fname, lua_tostring(L, -1));
+               zlog_err(
+                       "frrscript: failed loading script '%s.lua': out-of-memory error: %s",
+                       script_name, lua_tostring(L, -1));
                break;
        case LUA_ERRGCMM:
                zlog_err(
-                       "Failed loading script '%s': garbage collector error: %s",
-                       fname, lua_tostring(L, -1));
+                       "frrscript: failed loading script '%s.lua': garbage collector error: %s",
+                       script_name, lua_tostring(L, -1));
                break;
        case LUA_ERRFILE:
-               zlog_err("Failed loading script '%s': file read error: %s",
-                        fname, lua_tostring(L, -1));
+               zlog_err(
+                       "frrscript: failed loading script '%s.lua': file read error: %s",
+                       script_name, lua_tostring(L, -1));
                break;
        default:
-               zlog_err("Failed loading script '%s': unknown error: %s", fname,
-                        lua_tostring(L, -1));
+               zlog_err(
+                       "frrscript: failed loading script '%s.lua': unknown error: %s",
+                       script_name, lua_tostring(L, -1));
                break;
        }
 
index 85e7b15cd318df232b76b45349bbf80ef832c15a..1f234a38a9339c95ebefa2e39c5529937db7e272 100644 (file)
@@ -192,33 +192,31 @@ int _frrscript_call_lua(struct lua_function_state *lfs, int nargs);
  *    0 if the script ran successfully, nonzero otherwise.
  */
 
-#define frrscript_call(fs, f, ...)                                                                                   \
-       ({                                                                                                           \
-               struct lua_function_state lookup = {.name = f};                                                      \
-               struct lua_function_state *lfs;                                                                      \
-               lfs = hash_lookup(fs->lua_function_hash, &lookup);                                                   \
-               lfs == NULL ? ({                                                                                     \
-                       zlog_err(                                                                                    \
-                               "Lua script call: tried to call '%s' in '%s' which was not loaded",                  \
-                               f, fs->name);                                                                        \
-                       1;                                                                                           \
-               })                                                                                                   \
-                           : ({                                                                                     \
-                                     MAP_LISTS(ENCODE_ARGS, ##__VA_ARGS__);                                         \
-                                     _frrscript_call_lua(                                                           \
-                                             lfs, PP_NARG(__VA_ARGS__));                                            \
-                             }) != 0                                                                                \
-                                     ? ({                                                                           \
-                                               zlog_err(                                                            \
-                                                       "Lua script call: '%s' in '%s' returned non-zero exit code", \
-                                                       f, fs->name);                                                \
-                                               1;                                                                   \
-                                       })                                                                           \
-                                     : ({                                                                           \
-                                               MAP_LISTS(DECODE_ARGS,                                               \
-                                                         ##__VA_ARGS__);                                            \
-                                               0;                                                                   \
-                                       });                                                                          \
+#define frrscript_call(fs, f, ...)                                                                                                                   \
+       ({                                                                                                                                           \
+               struct lua_function_state lookup = {.name = f};                                                                                      \
+               struct lua_function_state *lfs;                                                                                                      \
+               lfs = hash_lookup(fs->lua_function_hash, &lookup);                                                                                   \
+               lfs == NULL ? ({                                                                                                                     \
+                       zlog_err(                                                                                                                    \
+                               "frrscript: '%s.lua': '%s': tried to call this function but it was not loaded",                                      \
+                               fs->name, f);                                                                                                        \
+                       1;                                                                                                                           \
+               })                                                                                                                                   \
+               : ({                                                                                                                                 \
+                         MAP_LISTS(ENCODE_ARGS, ##__VA_ARGS__);                                                                                     \
+                         _frrscript_call_lua(lfs, PP_NARG(__VA_ARGS__));                                                                            \
+                 }) != 0                                                                                                                            \
+                       ? ({                                                                                                                         \
+                                 zlog_err(                                                                                                          \
+                                         "frrscript: '%s.lua': '%s': this function called but returned non-zero exit code. No variables modified.", \
+                                         fs->name, f);                                                                                              \
+                                 1;                                                                                                                 \
+                         })                                                                                                                         \
+                       : ({                                                                                                                         \
+                                 MAP_LISTS(DECODE_ARGS, ##__VA_ARGS__);                                                                             \
+                                 0;                                                                                                                 \
+                         });                                                                                                                        \
        })
 
 /*