From 3cb6f6bb46edba67c0178653e17c488d78e096cc Mon Sep 17 00:00:00 2001 From: João M. M. da Silva + Alessandro Palmeira Date: Wed, 8 Aug 2012 18:17:26 -0300 Subject: [PATCH] [Mezuro] handle exceptions in base_tool --- plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb | 4 +++- plugins/mezuro/lib/kalibro/base_tool.rb | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb b/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb index f0e3f66..fba9b0e 100644 --- a/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb +++ b/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb @@ -6,12 +6,14 @@ class MezuroPluginMyprofileController < ProfileController def choose_base_tool @configuration_content = profile.articles.find(params[:id]) @base_tools = Kalibro::BaseTool.all_names + @base_tools = [] if @base_tools.first.is_a? Exception end def choose_metric @configuration_content = profile.articles.find(params[:id]) @base_tool = params[:base_tool] - @supported_metrics = Kalibro::BaseTool.find_by_name(@base_tool).supported_metrics + base_tool = Kalibro::BaseTool.find_by_name(@base_tool) + @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics end def new_metric_configuration diff --git a/plugins/mezuro/lib/kalibro/base_tool.rb b/plugins/mezuro/lib/kalibro/base_tool.rb index a57e16e..98e4c48 100644 --- a/plugins/mezuro/lib/kalibro/base_tool.rb +++ b/plugins/mezuro/lib/kalibro/base_tool.rb @@ -3,11 +3,19 @@ class Kalibro::BaseTool < Kalibro::Model attr_accessor :name, :description, :supported_metric def self.all_names - request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a + begin + request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a + rescue Exception => exception + [exception] + end end def self.find_by_name(base_tool_name) - new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] + begin + new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] + rescue Exception + nil + end end def supported_metric=(value) -- libgit2 0.21.2