[OpenSIPS-Users] PATCH: avp_db_query() return codes

Bogdan-Andrei Iancu bogdan at opensips.org
Thu Mar 3 09:46:46 CET 2011


Hi John,

Following our chat on IRC, I would like to update also the list here.

As said, currently we are looking into the possibility to extend the 
mechanism of error handling in OpenSIPS - the idea is, instead of keep 
testing all script functions for error cases, we should have an 
automatic way of catching and handling errors from script.

Testing functions (in script) one by one is not a nice an scalable 
approach, considering that all functions may return:
    - true for success
    - false for failure in processing
    - false for internal error
So for each function we need to handle by hand all possible return codes 
to catch the errors. I think this is not an option.

What I want to explore (topic for next week IRC meeting) is a generic 
system of catching and handling internal errors. Options are:
    1) extending the error route to be trigger not only by parsing 
errors, but also by other classes of internal errors (memory stuff, DB 
stuff, etc)
    2) adding a "try {} catch ; " instruction to divert execution to 
anther route when an internal error is triggered.


Regards,
Bogdan


John Khvatov wrote:
> Hello all.
>
> I wrote a small patch for avpops module:
> http://dev.sgu.ru/pub/0001-avp_db_query-improved-error-reporting.patch
>
> Current implementation of avp_db_query returns -1 on internal error or empty result. Thus, current function interface does not allow to write script with storage error handling.
>
> Patched avp_db_query() returns:
> -3 on internal error
> -1 on empty result
> 1 on success
>
> With patched avp_db_query() we can write following logic in opensips.cfg:
>
> avp_db_query("SELECT 1 WHERE false", "$avp(s:name)")
> if ($retcode == -3) {
>     xlog("Error while querying database. Handle error.");
> }
> else if ($retcode == -1) {
>     xlog("Handle empty result.");
> }
> else {
>     xlog("Handle result");
> }
>
> I've tested this patch with 1.6.4.
>
> Please, review my patch and apply to upstream.
>   


-- 
Bogdan-Andrei Iancu
OpenSIPS eBootcamp - 28th February 2011
OpenSIPS solutions and "know-how"




More information about the Users mailing list