1. Carl Friedrich Bolz
  2. Pyrolog

Commits

Carl Friedrich Bolz  committed 533ce1d

deal with missing error context

  • Participants
  • Parent commits eda6d5c
  • Branches default

Comments (0)

Files changed (2)

File prolog/interpreter/error.py

View file
  • Ignore whitespace
     def format_traceback(self, engine):
         out = ["Traceback (most recent call last):"]
         self.traceback._format(out)
-        context = self.sig_context.string()
-        if context == "throw/1":
-            context = ""
-        else:
-            context += ": "
+        context = ""
+        if self.sig_context is not None:
+            context = self.sig_context.string()
+            if context == "throw/1":
+                context = ""
+            else:
+                context += ": "
         out.append("%s%s" % (context, self.get_errstr(engine)))
         return "\n".join(out)
 

File prolog/interpreter/test/test_error.py

View file
  • Ignore whitespace
     g(_) :- _ is _.
 is/2: arguments not sufficiently instantiated"""
 
+def test_traceback_print_no_context():
+    e = get_engine("")
+    error = get_uncaught_error("f(1, Y).", e)
+    s = error.format_traceback(e)
+    assert s == """\
+Traceback (most recent call last):
+  File "<unknown>" in user:<user toplevel>/0
+Undefined procedure: f/2"""