Improved error handling and logging (#1187)

5 files changed