[Asterisk-code-review] main/sorcery: Provide log messages when a wizard does not su... (asterisk[13])

Matt Jordan asteriskteam at digium.com
Wed Jul 8 23:12:57 CDT 2015


Matt Jordan has uploaded a new change for review.

  https://gerrit.asterisk.org/849

Change subject: main/sorcery: Provide log messages when a wizard does not support an operation
......................................................................

main/sorcery: Provide log messages when a wizard does not support an operation

If a sorcery wizard does not support one of the 'optional' CRUD
operations (namely the CUD), log a WARNING message so we are aware of
why the operation failed. This also removes an assert in this case, as
the CUD operation may have been triggered by an external system, in
which case it is not a programming error but a configuration error.

Change-Id: Ifecd9df946d9deaa86235257b49c6e5e24423b53
---
M main/sorcery.c
1 file changed, 13 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/49/849/1

diff --git a/main/sorcery.c b/main/sorcery.c
index 4f547cd..b2e321a 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -1943,9 +1943,7 @@
 	const struct sorcery_details *details = arg;
 
 	if (!object_wizard->wizard->callbacks.create) {
-		ast_assert(0);
-		ast_log(LOG_ERROR, "Sorcery wizard '%s' doesn't contain a 'create' virtual function.\n",
-			object_wizard->wizard->callbacks.name);
+		ast_debug(5, "Sorcery wizard '%s' does not support creation\n", object_wizard->wizard->callbacks.name);
 		return 0;
 	}
 	return (!object_wizard->caching && !object_wizard->wizard->callbacks.create(details->sorcery, object_wizard->data, details->obj)) ? CMP_MATCH | CMP_STOP : 0;
@@ -2038,7 +2036,12 @@
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
 	const struct sorcery_details *details = arg;
 
-	return (object_wizard->wizard->callbacks.update && !object_wizard->wizard->callbacks.update(details->sorcery, object_wizard->data, details->obj) &&
+	if (!object_wizard->wizard->callbacks.update) {
+		ast_debug(5, "Sorcery wizard '%s' does not support updating\n", object_wizard->wizard->callbacks.name);
+		return 0;
+	}
+
+	return (!object_wizard->wizard->callbacks.update(details->sorcery, object_wizard->data, details->obj) &&
 		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
@@ -2106,7 +2109,12 @@
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
 	const struct sorcery_details *details = arg;
 
-	return (object_wizard->wizard->callbacks.delete && !object_wizard->wizard->callbacks.delete(details->sorcery, object_wizard->data, details->obj) &&
+	if (!object_wizard->wizard->callbacks.delete) {
+		ast_debug(5, "Sorcery wizard '%s' does not support deletion\n", object_wizard->wizard->callbacks.name);
+		return 0;
+	}
+
+	return (!object_wizard->wizard->callbacks.delete(details->sorcery, object_wizard->data, details->obj) &&
 		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/849
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifecd9df946d9deaa86235257b49c6e5e24423b53
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Matt Jordan <mjordan at digium.com>



More information about the asterisk-code-review mailing list