-
Notifications
You must be signed in to change notification settings - Fork 28
Description
In xpath.c, if an XPath does not include a namespace prefix, it calls ncx_find_any_object, which returns the first such object found. This issue reflects my spending an entire day tracking down a runtime error caused by this default with unhelpful error messages. Resolution might include changing the logic or enhancing error reporting.
In this particular case, I was debugging a SIL created from a yangdump stub. The YANG for the device in question includes a container called system. The auto-generated SIL code calls agt_cb_register_callback() with /system/... for that container and its child nodes, with no prefix specified. However, this results in ncx_find_any_object returning the ietf-system module, which it finds before mine, and which also contains a container called "system." Unfortunately, the result of all this is that agt_cb_register_callback() fails with ERR_NCX_DEFSEG_NOT_FOUND. And of course then I see on stderr that netconfd could not find the definition for /system/foo and look at my YANG and say "well why not? It's right there!" I ultimately had to compile libyuma with debugging symbols and run it in gdb to isolate the root cause of the error, which is not ideal in terms of the helpfulness of error messages.
A quick fix could include simply adding a log_debug3 or log_debug4 call at https://github.com/vlvassilev/yuma123/blob/d8d38672b9c92bcffc3383fc5c410b6dfe4a13de/netconf/src/ncx/xpath.c#L789C18-L789C33, indicating that in the absence of a prefix, the library is searching all modules and that spurious ERR_NCX_DEFSEG_NOT_FOUND results might be resolved by adding a prefix. It seems to me that agt_cb_register_callback could be made smart enough to add the relevant prefix to the XPath if none were supplied, but I haven't looked deeply at where that might happen.