Module: kamailio
Branch: master
Commit: 7712a856776d5cd9edec62bccc4b37bfd2ec2b8b
URL:
https://github.com/kamailio/kamailio/commit/7712a856776d5cd9edec62bccc4b37b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-12-21T15:21:03+01:00
app_ruby_proc: new function to handle error from ruby
---
Modified: src/modules/app_ruby_proc/app_ruby_api.c
---
Diff:
https://github.com/kamailio/kamailio/commit/7712a856776d5cd9edec62bccc4b37b…
Patch:
https://github.com/kamailio/kamailio/commit/7712a856776d5cd9edec62bccc4b37b…
---
diff --git a/src/modules/app_ruby_proc/app_ruby_api.c
b/src/modules/app_ruby_proc/app_ruby_api.c
index 4b4a7e3abf..f747da697e 100644
--- a/src/modules/app_ruby_proc/app_ruby_api.c
+++ b/src/modules/app_ruby_proc/app_ruby_api.c
@@ -77,6 +77,32 @@ sr_ruby_env_t *app_ruby_sr_env_get(void)
}
+static void ksr_ruby_error(int error)
+{
+ VALUE lasterr;
+ VALUE inclass;
+ VALUE message;
+ VALUE ary;
+ long c;
+
+ if (error == 0)
+ return;
+
+ lasterr = rb_gv_get("$!"); /* NOTRANSLATE */
+ inclass = rb_class_path(CLASS_OF(lasterr));
+ message = rb_obj_as_string(lasterr);
+ LM_ERR("error ruby script: class=%s, message=%s\n",
+ RSTRING_PTR(inclass), RSTRING_PTR(message));
+
+ if (!NIL_P(rb_errinfo())) {
+ ary = rb_funcall(rb_errinfo(), rb_intern("backtrace"), 0);
+ for (c=0; c<RARRAY_LEN(ary); ++c) {
+ LM_ERR("backtrace from %s\n",
+ RSTRING_PTR(RARRAY_PTR(ary)[c]));
+ }
+ }
+}
+
static int app_ruby_print_last_exception()
{
VALUE rException, rExceptStr;
@@ -108,7 +134,8 @@ int app_ruby_kemi_load_script(void)
if (state) {
/* got exception */
- app_ruby_print_last_exception();
+ //app_ruby_print_last_exception();
+ ksr_ruby_error(state);
LM_ERR("failed to load rb script file: %.*s (%d)\n",
_app_ruby_proc_load_file.len, _app_ruby_proc_load_file.s, state);
// return -1;
@@ -168,7 +195,8 @@ int app_ruby_proc_init_child(void)
if (state) {
/* handle exception */
- app_ruby_print_last_exception();
+ // app_ruby_print_last_exception();
+ ksr_ruby_error(state);
LM_ERR("test execution with error (res type: %d)\n", TYPE(rbres));
return -1;
} else {