Where are exceptions logged in context_change.py?

I’m trying to add a core hook with context_change.py and I’m getting an error in the tk-desktop2.log file that just says:

Exception raised while executing hook ‘[…]/context_change.py’

I cant seem to find anyway to view that exception so that I can debug.

2 Likes

otoh, the hook itself has a logger instance, so you could catch the exception inside it and log it like
self.logger.error(traceback.format_exc()) which should go to one of the standard logs (tk-shotgun or tk-desktop, I guess).

I’d first check the hook script for syntax, undefined variables, etc. which could be the first thing to trip it. A static checker in your editor/ide helps greatly with this.

2 Likes

I can replicate what you are seeing with the tk-desktop engine.
I’ve tracked down the issue there, and I suspect it is the same in tk-desktop2.

Although a log.exception is called when the hook errors, the way the logging is handled, means that the exception gets lost. I’m going to try and put a pull request together, as I’ve got something working on my end.
In the meantime, I would go with what Mois has suggested. Sorry for the frustration!

2 Likes

Actually for me, tk-desktop2 is generating a full error output. I get:

2019-11-28 12:31:23,391 [75895 ERROR sgtk.ext.tk-framework-shotgunutils.multi_context.external_runner] Could not start engine.
Traceback (most recent call last):
  File "/Users/philips1/Library/Application Support/Autodesk/Shotgun Create/ApplicationUpdates/b738a63/Shotgun Create.app/Contents/sgtk/bundle_cache/app_store/tk-framework-shotgunutils/v5.6.1/python/external_config/scripts/external_runner.py", line 110, in execute_command
    self._callback()
  File "/Users/philips1/Library/Application Support/Autodesk/Shotgun Create/ApplicationUpdates/b738a63/Shotgun Create.app/Contents/sgtk/bundle_cache/app_store/tk-framework-shotgunutils/v5.6.1/python/external_config/scripts/external_runner.py", line 371, in main
    arg_data.get("pre_cache") or False,
  File "/Users/philips1/Library/Application Support/Autodesk/Shotgun Create/ApplicationUpdates/b738a63/Shotgun Create.app/Contents/sgtk/bundle_cache/app_store/tk-framework-shotgunutils/v5.6.1/python/external_config/scripts/external_runner.py", line 277, in start_engine
    raise EngineStartupError(e)
EngineStartupError: bad things

Though as I say, tk-desktop does have an issue, for which I’ve now created a PR.

2 Likes

I found it. I had a self.log_debug() in there that it didn’t like. Changed it to self.logger.debug() and now it works fine.

3 Likes