Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#66093] Move Dentaku-error handling into the ErrorHandler

Tobias Dillmann6dd29458be1e
diff --git a/app/models/acts_as_customizable/calculated_value.rb b/app/models/acts_as_customizable/calculated_value.rb
index 5b1f3b54216..d9fc7af1277 100644
--- a/app/models/acts_as_customizable/calculated_value.rb
+++ b/app/models/acts_as_customizable/calculated_value.rb
@@ -75,21 +75,9 @@ module ActsAsCustomizable::CalculatedValue
value.is_a?(Numeric) ? value : nil
end
- errors = calculation.transform_values do |value|
- case value
- when Dentaku::ZeroDivisionError
- :zero_division
- when Dentaku::ArgumentError
- :missing_value
- when Dentaku::UnboundVariableError
- [:unbound_variable, value.unbound_variables]
- when Numeric
- # Calculation succeeded -> no error
- nil
- else
- :unknown
- end
- end.compact
+ errors = calculation.reject do |_, value|
+ value.is_a?(Numeric)
+ end
{ result:, errors: }
end
diff --git a/app/models/calculated_values/error_handler.rb b/app/models/calculated_values/error_handler.rb
index 9b912b8a804..b1865ae941e 100644
--- a/app/models/calculated_values/error_handler.rb
+++ b/app/models/calculated_values/error_handler.rb
@@ -80,14 +80,14 @@ module CalculatedValues
custom_field_id = to_id(cf_id)
case error
- in :zero_division
+ when Dentaku::ZeroDivisionError
ErrorContext.new(custom_field_id:, error_code: "ERROR_MATHEMATICAL")
- in :missing_value
+ when Dentaku::ArgumentError
build_missing_value_error_context(custom_field_id)
- in [:unbound_variable, disabled_fields]
+ when Dentaku::UnboundVariableError
ErrorContext.new(custom_field_id:,
error_code: "ERROR_DISABLED_VALUE",
- missing_custom_field_ids: disabled_fields.map { to_id(it) })
+ missing_custom_field_ids: error.unbound_variables.map { to_id(it) })
else
ErrorContext.new(custom_field_id:, error_code: "ERROR_UNKNOWN")
end