Pretty error message in failure dialog.
[guestfs-browser.git] / utils.ml
index 0bf18fa..9da9eb1 100644 (file)
--- a/utils.ml
+++ b/utils.ml
@@ -64,6 +64,24 @@ let connect_uri () = !connect_uri
 
 let utf8_rarrow = "\xe2\x86\x92"
 
+let pretty_string_of_exn =
+  function
+  | Guestfs.Error str ->
+      "Libguestfs error",
+      sprintf "libguestfs reported an error:
+
+%s
+
+To get more information about libguestfs errors, run guestfs-browser
+with the -x flag on the command line."
+        str
+
+  (* Add more exception types here as we come across them.  Last
+   * case below is the catch-all.
+   *)
+  | exn ->
+      "Error", Printexc.to_string exn
+
 let human_size i =
   if i < 1024L then
     sprintf "%Ld" i