summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-08-16 12:58:49 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-08-16 18:21:07 +0100
commit0f33a1d90c65f31444e14aef27d489706230939f (patch)
tree1b2f45cb9b73da38c4c5d0266a2aeb03c47c1cec
parent6f5447abe34dcddefa0885b006e65419fe84717a (diff)
downloadlibguestfs-0f33a1d90c65f31444e14aef27d489706230939f.tar.gz
libguestfs-0f33a1d90c65f31444e14aef27d489706230939f.tar.xz
libguestfs-0f33a1d90c65f31444e14aef27d489706230939f.zip
sysprep: Improve error messages.
-rw-r--r--sysprep/main.ml21
-rw-r--r--sysprep/utils.ml2
-rw-r--r--sysprep/utils.mli3
3 files changed, 25 insertions, 1 deletions
diff --git a/sysprep/main.ml b/sysprep/main.ml
index fbe0dbc4..0e8ea20d 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -186,7 +186,7 @@ read the man page virt-sysprep(1).
debug_gc, operations, g, selinux_relabel, quiet
-let () =
+let do_sysprep () =
(* Inspection. *)
match Array.to_list (g#inspect_os ()) with
| [] ->
@@ -248,6 +248,25 @@ let () =
(* Finished. *)
let () =
+ (try do_sysprep ()
+ with
+ | Failure msg -> (* from failwith/failwithf *)
+ eprintf (f_"sysprep operation failed: %s\n") msg;
+ exit 1
+ | Invalid_argument msg -> (* probably should never happen *)
+ eprintf (f_"sysprep operation failed: internal error: invalid argument: %s\n") msg;
+ exit 1
+ | Assert_failure (file, line, char) -> (* should never happen *)
+ eprintf (f_"sysprep operation failed: internal error: assertion failed at %s, line %d, char %d\n") file line char;
+ exit 1
+ | Not_found -> (* should never happen *)
+ eprintf (f_"sysprep operation failed: internal error: Not_found exception was thrown\n");
+ exit 1
+ | exn ->
+ eprintf (f_"sysprep operation failed: exception: %s\n")
+ (Printexc.to_string exn);
+ exit 1
+ );
g#shutdown ();
g#close ();
diff --git a/sysprep/utils.ml b/sysprep/utils.ml
index 003ae865..3b3ad8af 100644
--- a/sysprep/utils.ml
+++ b/sysprep/utils.ml
@@ -24,6 +24,8 @@ let (//) = Filename.concat
let () = Random.self_init ()
+let failwithf fs = ksprintf failwith fs
+
let string_prefix str prefix =
let n = String.length prefix in
String.length str >= n && String.sub str 0 n = prefix
diff --git a/sysprep/utils.mli b/sysprep/utils.mli
index 2b7e3208..0ecb8da4 100644
--- a/sysprep/utils.mli
+++ b/sysprep/utils.mli
@@ -21,6 +21,9 @@
val (//) : string -> string -> string
(** Filename concatenation. *)
+val failwithf : ('a, unit, string, 'b) format4 -> 'a
+(** Like [failwith] but supports printf-like arguments. *)
+
val string_prefix : string -> string -> bool
(** [string_prefix str prefix] returns true iff [prefix] is a prefix
of [str]. *)