From 0749697635678cbbe48bdf74e8be3e926e5b7d69 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Tue, 28 May 2019 18:15:39 +0200 Subject: Add prints when calling section callbacks Add error/warning prints when calling controller section 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-2469 Change-Id: I5808087d55b77d22a3878fd60015bc09063ac717 Signed-off-by: Jonathan Aillet --- ctl-lib/ctl-config.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index ef6038b..28d493e 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -153,15 +153,24 @@ int CtlConfigExec(afb_api_t apiHandle, CtlConfigT *ctlConfig) { #endif // Loop on every section and process config - int errcount=0; + int error; for (int idx = 0; ctlConfig->sections[idx].key != NULL; idx++) { - if (!ctlConfig->sections[idx].loadCB) - AFB_API_NOTICE(apiHandle, "CtlConfigLoad: notice empty section '%s'", ctlConfig->sections[idx].key); - else - errcount += ctlConfig->sections[idx].loadCB(apiHandle, &ctlConfig->sections[idx], NULL); + if (!ctlConfig->sections[idx].loadCB) { + AFB_API_NOTICE(apiHandle, "Notice empty section '%s'", ctlConfig->sections[idx].key); + continue; + } + + error = ctlConfig->sections[idx].loadCB(apiHandle, &ctlConfig->sections[idx], NULL); + if (error < 0) { + AFB_API_ERROR(apiHandle, "Error %i caught during call to '%s' section callback", error, ctlConfig->sections[idx].key); + return -idx; + } + else if (error > 0) { + AFB_API_WARNING(apiHandle, "Warning %i raised during call to '%s' section callback", error, ctlConfig->sections[idx].key); + } } - return errcount; + return 0; } CtlConfigT *CtlLoadMetaDataJson(afb_api_t apiHandle, json_object *ctlConfigJ, const char *prefix) { -- cgit 1.2.3-korg