]> mj.ucw.cz Git - moe.git/commitdiff
Better logging of exceptions
authorMartin Mares <mj@ucw.cz>
Fri, 14 Aug 2009 09:01:34 +0000 (11:01 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 14 Aug 2009 09:01:34 +0000 (11:01 +0200)
t/config
t/moe/batch.py
t/moe/log.py
t/moe/testcase.py
t/test.py

index 411443fc32ab39839f67ff1dd79353c00227f3d4..b84cb73e92bc820d80a382909c3c9e13cd5e3d3a 100644 (file)
--- a/t/config
+++ b/t/config
@@ -14,6 +14,8 @@ TESTCASE_RAW=${TEST}.raw
 # backward compatibility
 TESTCASE_PTS=${TEST}.pts
 
+DEBUG=1
+
 # HOOKS
 # TESTCASE_HOOKS
 
index 15f3b90a3420d363609f9507e6d927b05e99470e..9c839830fee892bdfb1d3e32951138a17a8741b7 100644 (file)
@@ -114,12 +114,18 @@ def test_in(e):
     if in_type == "file":
        in_name = e["IN_NAME"]
        e.log.verbose("Input file: %s (copied from %s)\n" % (in_name, os.path.join(e["PDIR"], inn)))
-       shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name))
+       try:
+           shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, in_name))
+       except IOError:
+           raise moe.MoeError, "Input file not found"
        if not is_interactive:
            sandbox_opts += " -i/dev/null"
     elif in_type == "stdio":
        e.log.verbose("Input file: <stdin> (copied from %s)\n" % os.path.join(e["PDIR"], inn))
-       shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin"))
+       try:
+           shutil.copyfile(os.path.join(tdir, inn), os.path.join(boxdir, ".stdin"))
+       except IOError:
+           raise moe.MoeError, "Input file not found"
        sandbox_opts += " -i.stdin"
     elif in_type == "none":
        e.log.verbose("Input file: <none>\n")
index 56dbe8f1f8dfa92d87b354ab9c21e60e5445a834..592fb846b047bd7b1952c3e6866080aa1074b67d 100644 (file)
@@ -2,8 +2,11 @@
 
 import sys
 import os
+import traceback
 
-progress_file = os.fdopen(os.dup(1), "w", 0)
+orig_stdout_fd = os.dup(1)
+orig_stderr_fd = os.dup(2)
+progress_file = os.fdopen(orig_stdout_fd, "w", 0)
 
 class MoeLog:
 
@@ -37,3 +40,8 @@ class MoeLog:
        self.log_file.flush()
 
 default = MoeLog()
+
+def fatal_exception():
+    os.dup2(orig_stderr_fd, 2)
+    traceback.print_exc()
+    sys.exit(1)
index e129a5305d88ac87d40ac9b3638302a561d8d307..36d335b7f72e7360b534e6f6a0e76cbcf16fc820 100644 (file)
@@ -6,6 +6,7 @@ import moe.config
 import moe.eval
 import moe.log
 import shutil
+import traceback
 
 def configure_test(e, test):
     e.cfgs = moe.config.MoeConfigStack(e.cfgs)
@@ -167,6 +168,11 @@ def wrap_run_test(e, test):
        run_test(e, test)
     except moe.MoeError, err:
        raise moe.TestError(err, "XX")
+    except Exception:
+       if e["DEBUG"]:
+           moe.log.fatal_exception()
+       traceback.print_exc(file = e.log.log_file)
+       raise moe.TestError("Internal exception", "XX")
 
 def conclude_test(e):
     stat = e.test_stat
index 37a21c9a12ae9136240fa2dcd601efe504af16f0..26d1a29e4b9bc7abf9b53f9a7adc4c487326ca83 100755 (executable)
--- a/t/test.py
+++ b/t/test.py
@@ -9,6 +9,7 @@ import moe.log
 import moe.eval
 import moe.pipeline
 import moe.batch
+import os
 
 e = moe.eval.Eval()
 
@@ -36,6 +37,8 @@ except moe.MoeError, err:
 except moe.SolutionError, err:
     e.stat["error"] = err
     e.log.shout("%s\n" % err)
+except Exception:
+    moe.log.fatal_exception()
 
 moe.log.default.progress_file.write("\nFinal status file:\n")
 e.stat.write(file=moe.log.default.progress_file)