diff --git a/cumulusci/core/exceptions.py b/cumulusci/core/exceptions.py index de8eabfd5f..a7a84d0695 100644 --- a/cumulusci/core/exceptions.py +++ b/cumulusci/core/exceptions.py @@ -114,3 +114,11 @@ class CommandException(CumulusCIException): class BrowserTestFailure(CommandException): """ Raise when browser tests fail """ pass + +class ApexCompilationException(CumulusCIException): + """ Raise when apex compilation fails """ + pass + +class ApexException(CumulusCIException): + """ Raise when an Apex Exception is raised in an org """ + pass \ No newline at end of file diff --git a/cumulusci/tasks/anonymous_apex.py b/cumulusci/tasks/anonymous_apex.py index 2b734b989d..8d9b0bae50 100644 --- a/cumulusci/tasks/anonymous_apex.py +++ b/cumulusci/tasks/anonymous_apex.py @@ -1,6 +1,8 @@ -import pprint - from cumulusci.tasks.salesforce import BaseSalesforceToolingApiTask +from cumulusci.core.exceptions import ApexCompilationException +from cumulusci.core.exceptions import ApexException +from cumulusci.core.exceptions import SalesforceException + class AnonymousApexTask(BaseSalesforceToolingApiTask): """ Executes a string of anonymous apex. """ @@ -23,4 +25,16 @@ def _run_task(self): path, result.status_code, result.content) - self.logger.info(pprint.pprint(result.json())) + # anon_results is an ExecuteAnonymous Result + # https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/sforce_api_calls_executeanonymous_result.htm + + anon_results = result.json() + if not anon_results['compiled']: + raise ApexCompilationException( + anon_results['line'], anon_results['compileProblem']) + + if not anon_results['success']: + raise ApexException( + anon_results['exceptionMessage'], anon_results['exceptionStackTrace']) + + self.logger.info('Anonymous Apex Success') \ No newline at end of file