Check for ctx being None before printing traceback

Fix for #471