aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Hinder <ian.hinder@aei.mpg.de>2011-09-24 13:59:17 +0200
committerIan Hinder <ian.hinder@aei.mpg.de>2011-09-24 13:59:17 +0200
commit18cf85fac56896748b760b8017eaba6cc8057265 (patch)
tree50188cd70f573d385352c64885cf2fa2a023853c
parentdc74cfdc90a00d7225a0533c70a7094216e74fb5 (diff)
RunKranc.m: Improve handling of errors and output
* Stop Mathematica from wrapping long lines with \ * Catch all types of exception, rather than just KrancError * Throw an exception if messages were generated during execution * Exit with a nonzero exit code if there was any error detected
-rw-r--r--Tools/MathematicaMisc/RunKranc.m58
1 files changed, 55 insertions, 3 deletions
diff --git a/Tools/MathematicaMisc/RunKranc.m b/Tools/MathematicaMisc/RunKranc.m
index abdb282..bd6dec6 100644
--- a/Tools/MathematicaMisc/RunKranc.m
+++ b/Tools/MathematicaMisc/RunKranc.m
@@ -11,7 +11,59 @@ Needs["KrancThorn`"];
If[Environment["KRANCVERBOSE"] == "yes",
SetDebugLevel[InfoFull]];
-exception = Catch[Get[script], KrancError];
-PrintError[exception];
+SetOptions["stdout", PageWidth -> Infinity];
-Quit[];
+(* I have not found a good way to abort on the first generated
+ message. All the attempts below are triggered on messages which
+ have been Quieted and I don't know a way to silently skip these.
+ Note that some built-in Mathematica functions seem to Quiet
+ messages internally, so even though no Quieting is done in Kranc,
+ such messages still cause an abort with the below methods.
+ Instead, we let the computation finish after messages have been
+ generated, and then use Check to throw an exception. *)
+
+(* ThrowMessage[text_, id1_, pat:_[_[id_, args___]]] := *)
+(* Module[{}, *)
+(* Print["text = ", text]; *)
+(* Print[StringForm[text,args], "Aborting due to message"]]; *)
+
+(* ThrowMessage2[args___] := *)
+(* Module[{}, *)
+(* Print["args = ", {args}]; *)
+(* Quit[]]; *)
+
+(* exception = Catch[Catch[ *)
+(* Internal`HandlerBlock[ *)
+(* (\* See http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/6314f05952ff5028 *\) *)
+(* {"MessageTextFilter", ThrowMessage[#1,#2,#3] &}, *)
+(* Get[script];None]], _]; *)
+
+(* exception = Catch[Catch[ *)
+(* Internal`HandlerBlock[ *)
+(* (\* See http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/6314f05952ff5028 *\) *)
+(* {"Message", Replace[#, _[_, True] :> ThrowMessage2[#]] &}, *)
+(* Get[script];None]], _]; *)
+
+(* Unprotect[Message]; *)
+
+(* $AbortMessage = True; *)
+
+(* Message[args___] := *)
+(* Block[{$AbortMessage = False}, *)
+(* If[{args}[[1]] =!= $Off[],Print["Message: ", args]; *)
+(* Message[args]]] /; $AbortMessage *)
+
+(* Protect[Message]; *)
+
+(* Quiet[Message[InverseFunction::ifun]]; *)
+
+exception = Catch[Catch[
+ Check[
+ Get[script];None,
+ ThrowError["Messages were generated - aborted"]]], _];
+
+If[exception =!= None,
+ Print["Exception:"];
+ PrintError[exception];
+ Quit[1],
+ Quit[]];