From ef3eb06afe2c813129fc86ab37b4b3bc722454e3 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 18 Jan 2011 12:55:35 +0100 Subject: [PATCH 1/3] Reporting controller: don't eat errors in development mode. log errors in production. --- app/controllers/cost_reports_controller.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index 59eef3348c..10eed31521 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -6,9 +6,23 @@ class CostReportsController < ApplicationController rescue_from Exception do |exception| session.delete(:report) - @custom_errors ||= [] - @custom_errors << l(:error_generic) - render :layout => !request.xhr? + if Rails.env == "production" + @custom_errors ||= [] + @custom_errors << l(:error_generic) + render :layout => !request.xhr? + logger.fatal <<-THE_ERROR + + ============================================================================== + REPORTING ERROR: + + #{exception.class}: #{exception.message} + #{exception.backtrace.join("\n ")} + ============================================================================== + + THE_ERROR + else + raise exception + end end helper :reporting From b97be4bbf30242c7bd2aba9f40541060cc5bd855 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 18 Jan 2011 12:58:59 +0100 Subject: [PATCH 2/3] Move #l from reporting helper to query utils, so it can be used in filters. --- app/helpers/reporting_helper.rb | 5 ----- app/models/cost_query/query_utils.rb | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/reporting_helper.rb b/app/helpers/reporting_helper.rb index 875f0f14c1..1a5383f540 100644 --- a/app/helpers/reporting_helper.rb +++ b/app/helpers/reporting_helper.rb @@ -1,11 +1,6 @@ module ReportingHelper include QueriesHelper - def l(*values) - return values.first if values.size == 1 and values.first.respond_to? :to_str - super - end - ## # For a given CostQuery::Filter filter, return an array of hashes, that contain # the partials that should be rendered (:name) for that filter and necessary diff --git a/app/models/cost_query/query_utils.rb b/app/models/cost_query/query_utils.rb index 8766baad20..c3e97d6e3d 100644 --- a/app/models/cost_query/query_utils.rb +++ b/app/models/cost_query/query_utils.rb @@ -14,6 +14,11 @@ module CostQuery::QueryUtils end end + def l(*values) + return values.first if values.size == 1 and values.first.respond_to? :to_str + I18n.t(*values) + end + def user_name(id) # we have no identity map... :( cache[:user_name][id] ||= User.find(id).name From 05a4a3106ca65ddd717beba8d2f1876a130de1ba Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Tue, 18 Jan 2011 13:01:08 +0100 Subject: [PATCH 3/3] Include Report::QueryUtils rather than CostQuery::QueryUtils to not trigger QueryUtils propagation, which will load all constants nested in CostQuery, thus resulting in a circular dependency. Propagation will take care of including CostQuery::QueryUtils later (not that we need it there, btw). --- app/models/cost_query/custom_field_mixin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/cost_query/custom_field_mixin.rb b/app/models/cost_query/custom_field_mixin.rb index dc3acb1071..db14ca6686 100644 --- a/app/models/cost_query/custom_field_mixin.rb +++ b/app/models/cost_query/custom_field_mixin.rb @@ -1,5 +1,5 @@ module CostQuery::CustomFieldMixin - include CostQuery::QueryUtils + include Report::QueryUtils attr_reader :custom_field SQL_TYPES = {