updated based on comment from @wasade
improved error messages