]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
prefill nit: better error messages
authorVladimír Čunát <vladimir.cunat@nic.cz>
Sun, 25 May 2025 08:17:44 +0000 (10:17 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Sun, 25 May 2025 08:17:44 +0000 (10:17 +0200)
Avoid the ugly cdata<const char *>: 0x7fe6202c7f80
Moreover the return code is -1 in my test case,
but that does not imply EPERM: Operation not permitted.
It was all unnecessary mess, including the pcall+error() pair.
Also avoid some double-wrapping by '[prefil]'.

daemon/zimport.h
modules/prefill/prefill.lua

index 5bbd992b08f98cd4b299f16e7b37d4dfcfef6a25..a73ae0363d3b58a4b9dca79f34343cd000fda53d 100644 (file)
@@ -34,6 +34,9 @@ typedef struct {
 } zi_config_t;
 
 /** Import zone from a file.
+ *
+ * \return kr_ok() if OK.  The return code may not be meaningful (e.g. -1),
+ *   but the error log should contain interesting information.
  *
  * Error can be directly returned in the first phase (parsing + ZONEMD);
  * otherwise it will be kr_ok() and config->cb gets (optionally) called finally.
index f4a42886e1e5386cdd3ef68a6630d910c9908d71..29cbc4ce9f4af37dffe60eb0608a8969b92b72ce 100644 (file)
@@ -73,14 +73,13 @@ local function download(url, fname)
        local file, rcode, errmsg
        file, errmsg = io.open(fname, 'w')
        if not file then
-               error(string.format("[prefil] unable to open file %s (%s)",
-                       fname, errmsg))
+               error(string.format("unable to open file %s: %s", fname, errmsg))
        end
 
        log_info(ffi.C.LOG_GRP_PREFILL, "downloading root zone to file %s ...", fname)
        rcode, errmsg = kluautil.kr_https_fetch(url, file, rz_ca_file)
        if rcode == nil then
-               error(string.format("[prefil] fetch of `%s` failed: %s", url, errmsg))
+               error(string.format("fetch of `%s` failed: %s", url, errmsg))
        end
 
        file:close()
@@ -93,10 +92,9 @@ local function import(fname)
        })
        if ret == 0 then
                log_info(ffi.C.LOG_GRP_PREFILL, "zone successfully parsed, import started")
+               return true
        else
-               error(string.format(
-                       "[prefil] zone import failed: %s", ffi.C.knot_strerror(ret)
-               ))
+               return false
        end
 end
 
@@ -122,8 +120,7 @@ function forward_references.fill_cache()
        end
        -- file is up to date, import
        -- import/filter function gets executed after resolver/module
-       local ok, errmsg = pcall(import, rz_local_fname)
-       if not ok then
+       if not import(rz_local_fname) then
                if rz_first_try then
                        rz_first_try = false
                        rz_cur_interval = 1
@@ -131,8 +128,8 @@ function forward_references.fill_cache()
                        rz_cur_interval = rz_import_error_interval
                                - math.random(rz_interval_randomizer_limit)
                end
-               log_info(ffi.C.LOG_GRP_PREFILL, "root zone import failed (%s), retry in %s",
-                       errmsg, display_delay(rz_cur_interval))
+               log_info(ffi.C.LOG_GRP_PREFILL, "root zone import failed, retry in %s",
+                       display_delay(rz_cur_interval))
        else
                -- re-download before TTL expires
                rz_cur_interval = (file_ttl - rz_interval_threshold