From 1ec55b98ed344d38a1980557cce89d4e980ba2b4 Mon Sep 17 00:00:00 2001 From: adamch Date: Tue, 11 Sep 2007 10:57:37 +0000 Subject: [PATCH] More verbose system error reporting --- exn.mlt | 6 ++++-- init.sig | 4 ++++ init.sml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/exn.mlt b/exn.mlt index c36e18a..b28705f 100644 --- a/exn.mlt +++ b/exn.mlt @@ -11,8 +11,10 @@ System error: <% Web.html name %> <% | OS.SysErr (name, SOME syserr) => %> System error: <% Web.html name %>: <% Web.html (OS.errorName syserr) %>: <% Web.htmlNl (OS.errorMsg syserr) %> -<% | IO.Io {name, function, ...} => %> -IO error: <% Web.html name %> for <% Web.html function %> +<% | IO.Io {name, function, cause, ...} => %> +IO error: <% Web.html name %> for <% Web.html function %>
+Cause: <% Web.html (Init.explain cause) %>
+Tokens:

<% Web.htmlNl (Init.tokens ()) %>

<% | Init.C.Sql msg => %> SQL: <% Web.htmlNl msg %> <% | Init.Access msg => %> diff --git a/init.sig b/init.sig index 39fe4ac..5c98e17 100644 --- a/init.sig +++ b/init.sig @@ -54,4 +54,8 @@ signature INIT = sig val listNodes : unit -> node list val nodeName : int -> string val nodeDebian : int -> string + + val explain : exn -> string + val tokens : unit -> string + val tokensForked : unit -> unit end diff --git a/init.sml b/init.sml index 4d55c90..22b27f6 100644 --- a/init.sml +++ b/init.sml @@ -203,4 +203,34 @@ fun nodeDebian id = [debian] => C.stringFromSql debian | row => rowError ("nodeDebian", row) +fun explain e = + case e of + OS.SysErr (name, sop) => + "System error: " ^ name ^ + (case sop of + NONE => "" + | SOME syserr => ": " ^ OS.errorName syserr ^ ": " ^ OS.errorMsg syserr) + | _ => "Unknown" + +fun tokens () = + let + val proc = Unix.execute ("/usr/bin/tokens", []) + val inf = Unix.textInstreamOf proc + + fun reader acc = + case TextIO.inputLine inf of + NONE => String.concat (rev acc) + | SOME s => reader (s :: acc) + in + reader [] + before (TextIO.closeIn inf; + ignore (Unix.reap proc)) + end + +fun tokensForked () = + case Posix.Process.fork () of + NONE => (OS.Process.system "/usr/bin/tokens >/tmp/tokens.child"; + OS.Process.exit OS.Process.success) + | _ => ignore (OS.Process.system "/usr/bin/tokens >/tmp/tokens.parent") + end -- 2.20.1