Skip to content

JIRA WDT-638 - Should never exit with uncaught exceptions #1157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 19, 2022
Merged
5 changes: 4 additions & 1 deletion core/src/main/python/compare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,7 @@ def format_message(key, *args):


if __name__ == "__main__":
main()
try:
main()
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, _logger)
5 changes: 4 additions & 1 deletion core/src/main/python/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
6 changes: 5 additions & 1 deletion core/src/main/python/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# imports from local packages start here
from wlsdeploy.aliases.aliases import Aliases
from wlsdeploy.aliases.wlst_modes import WlstModes
from wlsdeploy.exception import exception_helper
from wlsdeploy.exception.expection_types import ExceptionType
from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.tool.deploy import deployer_utils
Expand Down Expand Up @@ -258,4 +259,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
8 changes: 6 additions & 2 deletions core/src/main/python/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def __disconnect_domain(helper):
_method_name = '__disconnect_domain'

__logger.entering(class_name=_class_name, method_name=_method_name)

if __wlst_mode == WlstModes.ONLINE:
try:
helper.disconnect()
Expand Down Expand Up @@ -571,7 +572,6 @@ def main(args):
:return:
"""
_method_name = 'main'

__logger.entering(class_name=_class_name, method_name=_method_name)
for index, arg in enumerate(args):
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
Expand Down Expand Up @@ -638,4 +638,8 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)

5 changes: 4 additions & 1 deletion core/src/main/python/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
5 changes: 4 additions & 1 deletion core/src/main/python/extract_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
5 changes: 4 additions & 1 deletion core/src/main/python/model_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
6 changes: 5 additions & 1 deletion core/src/main/python/prepare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion

from oracle.weblogic.deploy.prepare import PrepareException
from wlsdeploy.exception import exception_helper
from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.tool.prepare.model_preparer import ModelPreparer
from wlsdeploy.tool.util import model_context_helper
Expand Down Expand Up @@ -109,4 +110,7 @@ def main():

if __name__ == "__main__" or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main()
try:
main()
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
5 changes: 4 additions & 1 deletion core/src/main/python/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
5 changes: 4 additions & 1 deletion core/src/main/python/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
5 changes: 4 additions & 1 deletion core/src/main/python/variable_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,7 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except:
exception_helper.__handleUnexpectedException(sys.exc_info(), _program_name, _class_name, __logger)
28 changes: 28 additions & 0 deletions core/src/main/python/wlsdeploy/exception/exception_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import oracle.weblogic.deploy.yaml.YamlException as JYamlException

from wlsdeploy.exception.expection_types import ExceptionType
from wlsdeploy.util.cla_utils import CommandLineArgUtil
from wlsdeploy.util import tool_exit

_EXCEPTION_TYPE_MAP = {
ExceptionType.ALIAS: 'create_alias_exception',
Expand Down Expand Up @@ -462,3 +464,29 @@ def _return_exception_params(*args, **kwargs):
arg_list = list(args)
error = kwargs.pop('error', None)
return arg_list, error

def __log_and_exit(logger, exit_code, class_name):
"""
Helper method to log the exiting message and call sys.exit()
:param logger: the logger to use
:param exit_code: the exit code to use
:param class_name: the class name to pass to the logger
"""
logger.exiting(result=exit_code, class_name=class_name, method_name=None)
tool_exit.end(None, exit_code)

def __handleUnexpectedException(ex, program_name, class_name, logger):
"""
Helper method to log and unexpected exception with exiting message and call sys.exit()
Note that the user sees the 'Unexpected' message along with the exception, but no stack trace.
The stack trace goes to the log
:param ex: the exception thrown
:param program_name: the program where it occurred
:param class_name: the class where it occurred
:param logger: the logger to use
"""
exc_type, exc_obj, exc_tb = sys.exc_info()
ee_string = traceback.format_exception(exc_type, exc_obj, exc_tb)
logger.severe('WLSDPLY-20035', program_name, exc_obj)
logger.finer('WLSDPLY-20036', program_name, ee_string)
__log_and_exit(logger, CommandLineArgUtil.PROG_ERROR_EXIT_CODE, class_name)
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,8 @@ WLSDPLY-20031={0} specified Variable File {1} is not a valid file: {2}
WLSDPLY-20032=No model specified and no model in archive, no validation performed
WLSDPLY-20033=Applying filter with name "{0}"
WLSDPLY-20034=Applying filter with ID "{0}"
WLSDPLY-20035={0} encountered an unexpected runtime exception. Please file an issue on GitHub and attach the log file and stdout. Error: {1}
WLSDPLY-20036={0} encountered an unexpected runtime exception. Stacktrace: {1}

# Messages for internal filters
WLSDPLY-20201=Unsupported attribute {0} at location {1} removed from model
Expand Down