You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/08/18 10:29:50 UTC
[14/50] [abbrv] ambari git commit: AMBARI-18162. Tracebacks of
exceptions should always be available (aonishuk)
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/branch-dev-logsearch
Commit: 4a2ee5009c3246a89a37fcf837eafad289fb7892
Parents: 7977523
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Tue Aug 16 17:55:29 2016 +0300
Committer: Andrew Onishuk <ao...@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()