The error message can be factored out to a private method or function for maintainability. Maybe the check too.