From a5cd92d9fa44dc73157d4225c211a5f546d30f93 Mon Sep 17 00:00:00 2001
From: bfs15 <bruno.serbena@gmail.com>
Date: Mon, 10 Jul 2017 09:52:25 -0300
Subject: [PATCH] Added error checking on infomap call

---
 lib/tasks/tag_clustering.rake | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/tasks/tag_clustering.rake b/lib/tasks/tag_clustering.rake
index bb024434c..efe132700 100644
--- a/lib/tasks/tag_clustering.rake
+++ b/lib/tasks/tag_clustering.rake
@@ -21,13 +21,12 @@ namespace :tag do
   desc 'Generate tag clusters'
   task :generate_clusters => [:environment] do
     # DEBUG = true
-
     graph_path = TagSearchService.file_path+".net"
     hash = create_hash()
+
     create_pajek_net_graph(hash, graph_path)
 
-    # puts "\nCalling infomap with the pajek graph\n\n" if DEBUG
-    system("infomap --ftree #{graph_path} #{TagSearchService.root_dir}")
+    infomap_ftree(graph_path, TagSearchService.root_dir)
 
     Rails.cache.delete(TagSearchService::CACHE_KEY)
   end # task
@@ -96,4 +95,14 @@ namespace :tag do
       end
     end
   end
+
+  def infomap_ftree(graph_path, out_dir)
+    # puts "\nCalling infomap with the pajek graph\n\n" if DEBUG
+    system("infomap --ftree #{graph_path} #{TagSearchService.root_dir}")
+    if $?.to_s != "0"
+      puts "-- Error on Infomap call"
+      puts "-- Make sure you have infomap in your executable path"
+      exit
+    end
+  end
 end # namespace
-- 
GitLab