From: Vladimír Čunát Date: Sun, 25 May 2025 08:17:44 +0000 (+0200) Subject: prefill nit: better error messages X-Git-Tag: v6.0.13~3^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86922c8cc96724f41c76c8b27e1c65977d62aedf;p=thirdparty%2Fknot-resolver.git prefill nit: better error messages Avoid the ugly cdata: 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]'. --- diff --git a/daemon/zimport.h b/daemon/zimport.h index 5bbd992b0..a73ae0363 100644 --- a/daemon/zimport.h +++ b/daemon/zimport.h @@ -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. diff --git a/modules/prefill/prefill.lua b/modules/prefill/prefill.lua index f4a42886e..29cbc4ce9 100644 --- a/modules/prefill/prefill.lua +++ b/modules/prefill/prefill.lua @@ -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