Remove code duplication in error_messages_for.