Re-introduce proper error handling that was removed in recent commits.