Commit 8a1bae5ee51ac485ecf7fc7526c25ac6da3b2b64
Committed by
Paulo Meireles
1 parent
6e951355
Exists in
staging
and in
42 other branches
[Mezuro] draft for exceptions
Showing
6 changed files
with
23 additions
and
10 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| @@ -5,7 +5,7 @@ class MezuroPluginProfileController < ProfileController | @@ -5,7 +5,7 @@ class MezuroPluginProfileController < ProfileController | ||
| 5 | def project_state | 5 | def project_state |
| 6 | @content = profile.articles.find(params[:id]) | 6 | @content = profile.articles.find(params[:id]) |
| 7 | project = @content.project | 7 | project = @content.project |
| 8 | - state = project.error.nil? ? project.state : "ERROR" | 8 | + state = project.kalibro_error.nil? ? project.state : "ERROR" |
| 9 | render :text => state | 9 | render :text => state |
| 10 | end | 10 | end |
| 11 | 11 |
plugins/mezuro/lib/kalibro/error.rb
| @@ -2,6 +2,10 @@ class Kalibro::Error < Kalibro::Model | @@ -2,6 +2,10 @@ class Kalibro::Error < Kalibro::Model | ||
| 2 | 2 | ||
| 3 | attr_accessor :error_class, :message, :stack_trace_element, :cause | 3 | attr_accessor :error_class, :message, :stack_trace_element, :cause |
| 4 | 4 | ||
| 5 | + def initialize(exception) | ||
| 6 | + @message = exception.message | ||
| 7 | + end | ||
| 8 | + | ||
| 5 | def stack_trace_element=(value) | 9 | def stack_trace_element=(value) |
| 6 | @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value | 10 | @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value |
| 7 | end | 11 | end |
plugins/mezuro/lib/kalibro/model.rb
| 1 | class Kalibro::Model | 1 | class Kalibro::Model |
| 2 | 2 | ||
| 3 | + attr_accessor :errors | ||
| 4 | + | ||
| 3 | def initialize(attributes={}) | 5 | def initialize(attributes={}) |
| 4 | attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | 6 | attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } |
| 7 | + @errors = [] | ||
| 5 | end | 8 | end |
| 6 | 9 | ||
| 7 | def to_hash(options={}) | 10 | def to_hash(options={}) |
| @@ -46,16 +49,22 @@ class Kalibro::Model | @@ -46,16 +49,22 @@ class Kalibro::Model | ||
| 46 | begin | 49 | begin |
| 47 | self.class.request(save_endpoint, save_action, save_params) | 50 | self.class.request(save_endpoint, save_action, save_params) |
| 48 | true | 51 | true |
| 49 | - rescue Exception => error | ||
| 50 | - false | 52 | + rescue Exception => exception |
| 53 | + add_error exception | ||
| 54 | + false | ||
| 51 | end | 55 | end |
| 52 | end | 56 | end |
| 57 | + | ||
| 58 | + def add_error(exception) | ||
| 59 | + @errors << exception | ||
| 60 | + end | ||
| 53 | 61 | ||
| 54 | def destroy | 62 | def destroy |
| 55 | - begin | 63 | + # begin |
| 56 | self.class.request(destroy_endpoint, destroy_action, destroy_params) | 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 | end | 68 | end |
| 60 | 69 | ||
| 61 | protected | 70 | protected |
plugins/mezuro/lib/kalibro/project.rb
| 1 | class Kalibro::Project < Kalibro::Model | 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 | def self.all_names | 5 | def self.all_names |
| 6 | request("Project", :get_project_names)[:project_name] | 6 | request("Project", :get_project_names)[:project_name] |
| @@ -15,7 +15,7 @@ class Kalibro::Project < Kalibro::Model | @@ -15,7 +15,7 @@ class Kalibro::Project < Kalibro::Model | ||
| 15 | end | 15 | end |
| 16 | 16 | ||
| 17 | def error=(value) | 17 | def error=(value) |
| 18 | - @error = Kalibro::Error.to_object value | 18 | + @kalibro_error = Kalibro::Error.to_object value |
| 19 | end | 19 | end |
| 20 | 20 | ||
| 21 | def process_project(days = '0') | 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,7 +51,7 @@ Kalibro::ProjectResult.first_result_after(name, date) | ||
| 51 | begin | 51 | begin |
| 52 | @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date) | 52 | @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date) |
| 53 | rescue Exception => error | 53 | rescue Exception => error |
| 54 | - errors.add_to_base(error.message) | 54 | + raise error |
| 55 | end | 55 | end |
| 56 | end | 56 | end |
| 57 | 57 |
plugins/mezuro/views/content_viewer/_project_error.rhtml
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | <p> | 2 | <p> |
| 3 | <%= "State when error ocurred: #{@project.state}" %> | 3 | <%= "State when error ocurred: #{@project.state}" %> |
| 4 | <br/> | 4 | <br/> |
| 5 | - <% error = @project.error %> | 5 | + <% error = @project.kalibro_error %> |
| 6 | <%= error.message %> | 6 | <%= error.message %> |
| 7 | <ul> | 7 | <ul> |
| 8 | <% error.stack_trace.each do |trace| %> | 8 | <% error.stack_trace.each do |trace| %> |