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

Just to let you all know I’ve just pushed out a new version of the tk-desktop engine (v2.4.13) that should mean it will now log the full traceback, when an error occurs within a project in SG Desktop.

2 Likes

I’m getting a similar issue with missing logs when trying to catch errors during the config startup. I’ve tried using the patch of tk-desktop but I’m still not seeing any logs.

I’ve got a framework that initializes during the tk-desktop bootstrap. However if there’s an error during the init it just doesn’t load the framework and there’s no trace in the logs. Ideally I’d want to see the full traceback if anything breaks.

Is this expected behavior or am I doing something wrong somewhere? Could it have anything to do with proxy based logging?

I get this in the logs:

DEBUG] [PROXY] Project-level tk-desktop engine has now switched back to proxy based logging.

2 Likes

Looks like a similar issue to be discussed here as well:

What version of tk-desktop are you running on both the project and site side?

1 Like

Ya seems more similar to the ticket about silently ignoring logging. FYI I’m on 2.4.14 for project level and then whatever is currently in tk-config-default for site (we’re currently tracking latest default).