From 0d0e561b703ca0f62f23a187cd4a7555ddc33f78 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Wed, 26 Jun 2019 15:37:47 +0200 Subject: Add prints when loading sections Add error/warning prints when calling loading sections callbacks. Move to next section if no callback is registered. Also, at section callback calls, return an error directly when the error is caught. Bug-AGL: SPEC-2568 Change-Id: I68495239b5b8e3b7ee03fcacc666a2b77375d616 Signed-off-by: Jonathan Aillet --- ctl-lib/ctl-config.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index 28d493e..cd89bc0 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -314,27 +314,35 @@ json_object* LoadAdditionalsFiles(afb_api_t apiHandle, CtlConfigT *ctlHandle, co } int CtlLoadSections(afb_api_t apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) { - int err; + int error; #ifdef CONTROL_SUPPORT_LUA - err= LuaConfigLoad(apiHandle, ctlHandle->prefix); - if (err) - return 1; + if (LuaConfigLoad(apiHandle, ctlHandle->prefix)) + return -1; #endif - err = 0; ctlHandle->sections = sections; for (int idx = 0; sections[idx].key != NULL; idx++) { json_object * sectionJ; - int done = json_object_object_get_ex(ctlHandle->configJ, sections[idx].key, §ionJ); - if (done) { + if (json_object_object_get_ex(ctlHandle->configJ, sections[idx].key, §ionJ)) { sections[idx].prefix = ctlHandle->prefix; json_object* updatedSectionJ = LoadAdditionalsFiles(apiHandle, ctlHandle, sections[idx].key, sectionJ); - err += sections[idx].loadCB(apiHandle, §ions[idx], updatedSectionJ); + + if (!sections[idx].loadCB) { + AFB_API_NOTICE(apiHandle, "Notice empty section '%s'", sections[idx].key); + continue; + } + + error = sections[idx].loadCB(apiHandle, §ions[idx], updatedSectionJ); + if (error < 0) { + AFB_API_ERROR(apiHandle, "Error %i caught during call to '%s' section callback", error, sections[idx].key); + return -(idx + 1); + } + else if (error > 0) { + AFB_API_WARNING(apiHandle, "Warning %i raised during call to '%s' section callback", error, sections[idx].key); + } } } - if (err) - return 1; return 0; } -- cgit 1.2.3-korg