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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/main/python/compare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#
# If the flag is not provided then all output is written to the standard out.
#
import exceptions
import os
import sets
import sys
Expand Down Expand Up @@ -348,4 +349,9 @@ def format_message(key, *args):


if __name__ == "__main__":
main()
try:
main()
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, _logger)
9 changes: 8 additions & 1 deletion core/src/main/python/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

The main module for the WLSDeploy tool to create empty domains.
"""
import exceptions
import os
import sys

from java.io import IOException
from java.lang import IllegalArgumentException
from java.lang import String
Expand Down Expand Up @@ -376,4 +378,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
9 changes: 8 additions & 1 deletion core/src/main/python/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

The entry point for the deployApps tool.
"""
import exceptions
import os
import sys

Expand All @@ -17,6 +18,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 +260,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
11 changes: 9 additions & 2 deletions core/src/main/python/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

The entry point for the discoverDomain tool.
"""
import exceptions
import os
import sys

Expand Down Expand Up @@ -234,6 +235,7 @@ def __discover(model_context, aliases, credential_injector, helper):
model = Model()
base_location = LocationContext()
__connect_to_domain(model_context, helper)

try:
_add_domain_name(base_location, aliases, helper)
DomainInfoDiscoverer(model_context, model.get_model_domain_info(), base_location, wlst_mode=__wlst_mode,
Expand Down Expand Up @@ -367,6 +369,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 +574,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 +640,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
8 changes: 7 additions & 1 deletion core/src/main/python/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

The main module for the WLSDeploy tool to encrypt passwords.
"""
import exceptions
import sys

from java.io import IOException
Expand Down Expand Up @@ -253,4 +254,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
8 changes: 7 additions & 1 deletion core/src/main/python/extract_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

The entry point for the extractDomainResource tool.
"""
import exceptions
import sys

from oracle.weblogic.deploy.deploy import DeployException
Expand Down Expand Up @@ -158,4 +159,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
9 changes: 8 additions & 1 deletion core/src/main/python/model_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

The entry point for the modelHelp tool.
"""
import exceptions
import os
import sys

from oracle.weblogic.deploy.util import CLAException
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion

Expand Down Expand Up @@ -133,4 +135,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
11 changes: 9 additions & 2 deletions core/src/main/python/prepare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
#
# This code prepare a list of models for deploying to WebLogic Kubernetes Operator Environment.

import exceptions
import sys
import traceback

import sys
from oracle.weblogic.deploy.util import CLAException
from oracle.weblogic.deploy.util import PyWLSTException
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 +111,9 @@ def main():

if __name__ == "__main__" or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main()
try:
main()
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
8 changes: 7 additions & 1 deletion core/src/main/python/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

The entry point for the updateDomain tool.
"""
import exceptions
import os
import sys

Expand Down Expand Up @@ -309,4 +310,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
10 changes: 9 additions & 1 deletion core/src/main/python/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

The WLS Deploy tooling entry point for the validateModel tool.
"""

import copy
import exceptions
import sys

from java.util.logging import Level

from oracle.weblogic.deploy.logging import WLSDeployLogEndHandler
Expand Down Expand Up @@ -196,4 +199,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
8 changes: 7 additions & 1 deletion core/src/main/python/variable_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

The entry point for the injectVariables tool.
"""
import exceptions
import sys

from java.io import File
Expand Down Expand Up @@ -204,4 +205,9 @@ def main(args):

if __name__ == '__main__' or __name__ == 'main':
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
main(sys.argv)
try:
main(sys.argv)
except exceptions.SystemExit, ex:
raise ex
except (exceptions.Exception, java.lang.Exception), ex:
exception_helper.__handle_unexpected_exception(ex, _program_name, _class_name, __logger)
34 changes: 34 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,35 @@ 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 __handle_unexpected_exception(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
"""
logger.severe('WLSDPLY-20035', program_name, sys.exc_info()[0])

if hasattr(ex, 'stackTrace'):
# this works best for java exceptions, and gets the full stacktrace all the way back to weblogic.WLST
logger.finer('WLSDPLY-20036', program_name, ex.stackTrace)
else:
# this is for Python exceptions
# Note: since this is Python 2, it seems we can only get the traceback object via sys.exc_info, and of course only
# while in the except block handling code
logger.finer('WLSDPLY-20036', program_name, traceback.format_exception(type(ex), ex, sys.exc_info()[2]))
__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. Exception: {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