Check for ctx being None before printing traceback

Fixes #471