From 72b3d672735f624064431cbb0751d3cc3b08b6ba Mon Sep 17 00:00:00 2001
From: mahesh
Date: Fri, 27 Oct 2017 02:22:08 +0530
Subject: Add traceback for exceptions
---
yaksh/python_assertion_evaluator.py | 22 +++++++++++-----------
yaksh/templates/exam.html | 28 +++++++++++++++++++++-------
2 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py
index 35a08ec..af89fc3 100644
--- a/yaksh/python_assertion_evaluator.py
+++ b/yaksh/python_assertion_evaluator.py
@@ -75,23 +75,23 @@ class PythonAssertionEvaluator(BaseEvaluator):
except TimeoutException:
raise
except AssertionError:
- type, _, tb = sys.exc_info()
- tb_info = traceback.extract_tb(tb)
- filename, line, func, text = tb_info[-1]
+ exc_type, exc_value, exc_tb = sys.exc_info()
value = "Expected answer from the test case didnt match the output"
err = {"type": "assertion",
"test_case": self.test_case,
- "exception": type.__name__,
- "message": value
+ "exception": exc_type.__name__,
+ "message": value,
}
except Exception:
- type, value, tb = sys.exc_info()
- tb_info = traceback.extract_tb(tb)
- filename, line, func, text = tb_info[-1]
+ exc_type, exc_value, exc_tb = sys.exc_info()
+ tb_list = traceback.format_exception(exc_type, exc_value, exc_tb)
+ if len(tb_list) > 2:
+ del tb_list[1:3]
+
err = {"type": "assertion",
- "test_case": self.test_case,
- "exception": type.__name__,
- "message": str(value)
+ "traceback": "".join(tb_list),
+ "exception": exc_type.__name__,
+ "message": str(exc_value)
}
else:
diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html
index 7b6d54e..8b573d4 100644
--- a/yaksh/templates/exam.html
+++ b/yaksh/templates/exam.html
@@ -91,17 +91,31 @@
{% if not error.type %}
{{error|safe}}
{% elif error.type == 'assertion' %}
- We tried the calling your function with the following test case:
- {{error.test_case}}
-
- But the following error took place:
-
- Exception Name |
+ {% if error.test_case %}
+
+
+
+ We tried calling your function with the following test case: |
+ {{error.test_case}} |
+
+
+ {% endif %}
+ The following error took place:
+
+
+
+ Exception Name: |
{{error.exception}}
|
- Exception Message | {{error.message}} |
+ Exception Message: | {{error.message}} |
+
+
+ {% if error.traceback %}
+ Full exception: |
+ {{error.traceback}} |
+ {% endif %}
{% elif error.type == 'stdio' %}
--
cgit