Skip to content

Commit 49c47e6

Browse files
authored
SHOT-4440: Improve error handling (#93)
* Override the python global exception hook to ensure uncaught exceptions are logged as an error to the sgtk log file (e.g. tk-alias.log)
1 parent e5d304a commit 49c47e6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

python/tk_framework_alias_utils/plugin_bootstrap.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ def toolkit_plugin_bootstrap(
5353
log_handler, log_file_path = log.get_sgtk_logger(sgtk)
5454
logger.debug("Added bootstrap log hander to root logger...")
5555

56+
# Override the global exception hook for catching and reporting uncaught
57+
# exceptions
58+
def global_exception_hook(exctype, value, tb):
59+
# Log the error with the sgtk logger (e.g. write to tk-alias.log)
60+
logger.error("Uncaught Exception", exc_info=(exctype, value, tb))
61+
# Call the python default exception handler
62+
sys.__excepthook__(exctype, value, tb)
63+
64+
sys.excepthook = global_exception_hook
65+
5666
# Toolkit bootstrap may take some time when many bundles need to be
5767
# downloaded and cached. When not in debug mode, launch a PowerShell
5868
# window to indicate to the user that the plugin is bootstrapping. At this
@@ -135,6 +145,7 @@ def toolkit_plugin_bootstrap(
135145

136146
# Log message to Alias prompt indicating that Flow Production Tracking is ready
137147
engine.alias_py.log_to_prompt("Flow Production Tracking initialized")
148+
138149
except Exception as e:
139150
# There are no specific exceptions that are expected, so catch all and
140151
# log the error so that the Alias plugin does not crash, or fail

0 commit comments

Comments
 (0)