From 88908fd46de5694d66eb1fe0cc3467d4a393ad93 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 31 Mar 2024 16:33:34 +0000 Subject: [PATCH] lua: Don't raise an error if a network cannot be found The lookup function now returns nil which is easier to handle than catching a Lua error. Signed-off-by: Michael Tremer --- src/lua/database.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lua/database.c b/src/lua/database.c index 841041d..aada739 100644 --- a/src/lua/database.c +++ b/src/lua/database.c @@ -174,8 +174,17 @@ static int Database_lookup(lua_State* L) { // Perform lookup r = loc_database_lookup_from_string(self->db, address, &network); - if (r) - return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno)); + if (r) { + switch (errno) { + // Return nil if the network was not found + case ENOENT: + lua_pushnil(L); + return 1; + + default: + return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno)); + } + } // Create a network object r = create_network(L, network); -- 2.39.5