[Libguestfs] [PATCH 1/2] ruby: Print exceptions thrown by event callbacks.

Richard W.M. Jones rjones at redhat.com
Tue Jun 7 21:35:32 UTC 2016


---
 generator/ruby.ml | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/generator/ruby.ml b/generator/ruby.ml
index 97ccfdc..0f71ccc 100644
--- a/generator/ruby.ml
+++ b/generator/ruby.ml
@@ -404,15 +404,17 @@ event_callback_wrapper_wrapper (VALUE argvv)
   return Qnil;
 }
 
+/* Callbacks aren't supposed to throw exceptions.  We just print the
+ * exception on stderr and hope for the best.
+ */
 static VALUE
 event_callback_handle_exception (VALUE not_used, VALUE exn)
 {
-  /* Callbacks aren't supposed to throw exceptions. */
-  fprintf (stderr, \"libguestfs: exception in callback!\\n\");
+  volatile VALUE message;
 
-  /* XXX We could print the exception, but it's very difficult from
-   * a Ruby extension.
-   */
+  message = rb_funcall (exn, rb_intern (\"to_s\"), 0);
+  fprintf (stderr, \"libguestfs: exception in callback: %%s\\n\",
+           StringValueCStr (message));
 
   return Qnil;
 }
-- 
2.7.4




More information about the Libguestfs mailing list