ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject ambari git commit: AMBARI-18162. Tracebacks of exceptions should always be available (aonishuk)
Date Tue, 16 Aug 2016 14:55:36 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 797752341 -> 4a2ee5009


AMBARI-18162. Tracebacks of exceptions should always be available (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4a2ee500
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4a2ee500
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4a2ee500

Branch: refs/heads/trunk
Commit: 4a2ee5009c3246a89a37fcf837eafad289fb7892
Parents: 7977523
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Tue Aug 16 17:55:29 2016 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Tue Aug 16 17:55:29 2016 +0300

----------------------------------------------------------------------
 .../python/resource_management/core/exceptions.py     | 14 +++++++++++++-
 .../resource_management/libraries/script/script.py    |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4a2ee500/ambari-common/src/main/python/resource_management/core/exceptions.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/core/exceptions.py b/ambari-common/src/main/python/resource_management/core/exceptions.py
index 25e7993..b224fb3 100644
--- a/ambari-common/src/main/python/resource_management/core/exceptions.py
+++ b/ambari-common/src/main/python/resource_management/core/exceptions.py
@@ -20,10 +20,22 @@ Ambari Agent
 
 """
 
+import sys
+import traceback
+
 __all__ = ["Fail", "ExecuteTimeoutException", "InvalidArgument", "ClientComponentHasNoStatus",
"ComponentIsNotRunning"]
 
 class Fail(Exception):
-  pass
+  def __init__(self, message="", print_cause=True):
+    self.print_cause = print_cause
+    self.cause_traceback = traceback.format_exc()
+
+    super(Fail, self).__init__(message)
+
+  def pre_raise(self):
+    if self.print_cause and self.cause_traceback != 'None\n':
+      sys.stderr.write(self.cause_traceback)
+      sys.stderr.write("\nThe above exception was the cause of the following exception:\n\n")
 
 class ExecuteTimeoutException(Fail):
   pass

http://git-wip-us.apache.org/repos/asf/ambari/blob/4a2ee500/ambari-common/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/script/script.py
b/ambari-common/src/main/python/resource_management/libraries/script/script.py
index f8c4c4e..c5b3799 100644
--- a/ambari-common/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-common/src/main/python/resource_management/libraries/script/script.py
@@ -278,6 +278,9 @@ class Script(object):
           self.pre_start()
         
         method(env)
+    except Fail as ex:
+      ex.pre_raise()
+      raise
     finally:
       if self.should_expose_component_version(self.command_name):
         self.save_component_version_to_structured_out()


Mime
View raw message