From 4d6899ee91ddaa7b5758de50fd2cc09b46e6a7f3 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 7 Jun 2016 20:52:04 +0100 Subject: [PATCH] ruby: Print exceptions thrown by event callbacks. --- generator/ruby.ml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/generator/ruby.ml b/generator/ruby.ml index 97ccfdc42..0f71cccb2 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; }