nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: SFDO-Tooling/CumulusCI
Pull request #818 (2018-10-12 13:43:52)

Print a more useful error than 'ApexException' for anon apex task
# Critical Changes

# Changes
* Improved error messages for errors while executing anonymous Apex

# Issues Closed



Patch:
diff --git a/cumulusci/cli/cci.py b/cumulusci/cli/cci.py
index 8fcfcec1d..3ca09016c 100644
--- a/cumulusci/cli/cci.py
+++ b/cumulusci/cli/cci.py
@@ -1004,7 +1004,7 @@ def task_run(config, task_name, org, o, debug, debug_before, debug_after, no_pro
         handle_exception_debug(config, debug, throw_exception=exception)
     except (CumulusCIFailure, ScratchOrgException) as e:
         # Expected failure; report without traceback
-        exception = click.ClickException("Failed: {}".format(e.__class__.__name__))
+        exception = click.ClickException(str(e) or e.__class__.__name__)
         handle_exception_debug(config, debug, throw_exception=exception)
     except Exception:
         # Unexpected exception; log to sentry and raise
diff --git a/cumulusci/core/exceptions.py b/cumulusci/core/exceptions.py
index 483309c84..624bac150 100644
--- a/cumulusci/core/exceptions.py
+++ b/cumulusci/core/exceptions.py
@@ -206,13 +206,18 @@ class BrowserTestFailure(CumulusCIFailure):
 class ApexCompilationException(CumulusCIFailure):
     """ Raise when apex compilation fails """
 
-    pass
+    def __str__(self):
+        line, problem = self.args
+        return "Apex compilation failed on line {}: {}".format(line, problem)
 
 
 class ApexException(CumulusCIFailure):
     """ Raise when an Apex Exception is raised in an org """
 
-    pass
+    def __str__(self):
+        message, stacktrace = self.args
+        stacktrace = "\n  ".join(stacktrace.splitlines())
+        return "Apex error: {}\n  Stacktrace:\n  {}".format(message, stacktrace)
 
 
 class PushApiObjectNotFound(CumulusCIException):


Test patch:
diff --git a/cumulusci/core/tests/test_exceptions.py b/cumulusci/core/tests/test_exceptions.py
new file mode 100644
index 000000000..de1711442
--- /dev/null
+++ b/cumulusci/core/tests/test_exceptions.py
@@ -0,0 +1,17 @@
+import unittest
+
+from cumulusci.core import exceptions
+
+
+class TestExceptions(unittest.TestCase):
+    def test_ApexCompilationException_str(self):
+        err = exceptions.ApexCompilationException(42, "Too many braces")
+        self.assertEqual(
+            "Apex compilation failed on line 42: Too many braces", str(err)
+        )
+
+    def test_ApexException(self):
+        err = exceptions.ApexException("Things got real", "Anon line 1")
+        self.assertEqual(
+            "Apex error: Things got real\n  Stacktrace:\n  Anon line 1", str(err)
+        )