aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-26 15:37:47 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-07-17 12:04:54 +0200
commit0d0e561b703ca0f62f23a187cd4a7555ddc33f78 (patch)
tree39dbdd28a34de5fc4afaa4d2d921da09dee5aafd
parentc1acf36459ce3046b7fc46f26328ce408a2f49fb (diff)
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 <jonathan.aillet@iot.bzh>
-rw-r--r--ctl-lib/ctl-config.c28
1 files 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, &sectionJ);
- if (done) {
+ if (json_object_object_get_ex(ctlHandle->configJ, sections[idx].key, &sectionJ)) {
sections[idx].prefix = ctlHandle->prefix;
json_object* updatedSectionJ = LoadAdditionalsFiles(apiHandle, ctlHandle, sections[idx].key, sectionJ);
- err += sections[idx].loadCB(apiHandle, &sections[idx], updatedSectionJ);
+
+ if (!sections[idx].loadCB) {
+ AFB_API_NOTICE(apiHandle, "Notice empty section '%s'", sections[idx].key);
+ continue;
+ }
+
+ error = sections[idx].loadCB(apiHandle, &sections[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;
}