Commit d23a42e4c110268892d79fbe6b9121f5a895b14a

Authored by João M. M. da Silva + Alessandro Palmeira
Committed by Paulo Meireles
1 parent f4012a36

[Mezuro] draft for exceptions

plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... ... @@ -5,7 +5,7 @@ class MezuroPluginProfileController < ProfileController
5 5 def project_state
6 6 @content = profile.articles.find(params[:id])
7 7 project = @content.project
8   - state = project.error.nil? ? project.state : "ERROR"
  8 + state = project.kalibro_error.nil? ? project.state : "ERROR"
9 9 render :text => state
10 10 end
11 11  
... ...
plugins/mezuro/lib/kalibro/error.rb
... ... @@ -2,6 +2,10 @@ class Kalibro::Error < Kalibro::Model
2 2  
3 3 attr_accessor :error_class, :message, :stack_trace_element, :cause
4 4  
  5 + def initialize(exception)
  6 + @message = exception.message
  7 + end
  8 +
5 9 def stack_trace_element=(value)
6 10 @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value
7 11 end
... ...
plugins/mezuro/lib/kalibro/model.rb
1 1 class Kalibro::Model
2 2  
  3 + attr_accessor :errors
  4 +
3 5 def initialize(attributes={})
4 6 attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
  7 + @errors = []
5 8 end
6 9  
7 10 def to_hash(options={})
... ... @@ -46,16 +49,22 @@ class Kalibro::Model
46 49 begin
47 50 self.class.request(save_endpoint, save_action, save_params)
48 51 true
49   - rescue Exception => error
50   - false
  52 + rescue Exception => exception
  53 + add_error exception
  54 + false
51 55 end
52 56 end
  57 +
  58 + def add_error(exception)
  59 + @errors << exception
  60 + end
53 61  
54 62 def destroy
55   - begin
  63 + # begin
56 64 self.class.request(destroy_endpoint, destroy_action, destroy_params)
57   - rescue Exception
58   - end
  65 + #rescue Exception => exception
  66 + # add_error exception
  67 + #end
59 68 end
60 69  
61 70 protected
... ...
plugins/mezuro/lib/kalibro/project.rb
1 1 class Kalibro::Project < Kalibro::Model
2 2  
3   - attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error
  3 + attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :kalibro_error
4 4  
5 5 def self.all_names
6 6 request("Project", :get_project_names)[:project_name]
... ... @@ -15,7 +15,7 @@ class Kalibro::Project &lt; Kalibro::Model
15 15 end
16 16  
17 17 def error=(value)
18   - @error = Kalibro::Error.to_object value
  18 + @kalibro_error = Kalibro::Error.to_object value
19 19 end
20 20  
21 21 def process_project(days = '0')
... ...
plugins/mezuro/lib/mezuro_plugin/project_content.rb
... ... @@ -51,7 +51,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
51 51 begin
52 52 @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date)
53 53 rescue Exception => error
54   - errors.add_to_base(error.message)
  54 + raise error
55 55 end
56 56 end
57 57  
... ...
plugins/mezuro/views/content_viewer/_project_error.rhtml
... ... @@ -2,7 +2,7 @@
2 2 <p>
3 3 <%= "State when error ocurred: #{@project.state}" %>
4 4 <br/>
5   - <% error = @project.error %>
  5 + <% error = @project.kalibro_error %>
6 6 <%= error.message %>
7 7 <ul>
8 8 <% error.stack_trace.each do |trace| %>
... ...