Better error handling and logging.
#3481