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

Remove instance variables in error helper and lint

Oliver Günther7e6a923790fc
diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb
index a41b5fb2101..507828b3fc9 100644
--- a/app/helpers/errors_helper.rb
+++ b/app/helpers/errors_helper.rb
@@ -27,34 +27,34 @@
#++
module ErrorsHelper
- def render_400(options = {})
- @project = nil
+ def render_400(options = {}) # rubocop:disable Naming/VariableNumber
+ unset_template_magic
render_error({ message: :notice_bad_request, status: 400 }.merge(options))
false
end
- def render_403(options = {})
- @project = nil
+ def render_403(options = {}) # rubocop:disable Naming/VariableNumber
+ unset_template_magic
render_error({ message: :notice_not_authorized, status: 403 }.merge(options))
false
end
- def render_404(options = {})
+ def render_404(options = {}) # rubocop:disable Naming/VariableNumber
render_error({ message: :notice_file_not_found, status: 404 }.merge(options))
false
end
- def render_500(options = {})
- message = t(:notice_internal_server_error, app_title: Setting.app_title)
-
+ def render_500(options = {}) # rubocop:disable Naming/VariableNumber
unset_template_magic
+ message = t(:notice_internal_server_error, app_title: Setting.app_title)
+
# Append error information
if current_user.admin?
options[:message_details] = get_additional_message
end
- render_error({ message: }.merge(options))
+ render_error({ message:, status: 500 }.merge(options))
false
end
@@ -80,39 +80,34 @@ module ErrorsHelper
end
# Renders an error response
- def render_error(arg)
+ def render_error(arg) # rubocop:disable Metrics/AbcSize
arg = { message: arg } unless arg.is_a?(Hash)
- @status = arg[:status] || 500
- @message = arg[:message]
+ status = arg[:status] || 500
+ message = arg[:message]
- if @status >= 500
- op_handle_error(arg[:exception] || "[Error #@status] #@message", payload: arg[:payload])
+ if status >= 500
+ op_handle_error(arg[:exception] || "[Error #status] #message", payload: arg[:payload])
end
- @message = I18n.t(@message) if @message.is_a?(Symbol)
- @message_details = arg[:message_details]
+ message = I18n.t(message) if message.is_a?(Symbol)
+ message_details = arg[:message_details]
respond_to do |format|
format.html do
- error_message = "[#{I18n.t(:error_code, code: @status)}] #{@message}\n#{@message_details}"
+ error_message = "[#{I18n.t(:error_code, code: status)}] #{message}\n#{message_details}"
flash.now[:op_primer_flash] = { scheme: :danger, message: error_message, dismiss_scheme: :none }
- render template: "common/error", layout: use_layout, status: @status
+ render template: "common/error",
+ layout: use_layout,
+ status:,
+ locals: { status:, params: }
end
format.any do
- head @status
+ head status
end
end
end
def unset_template_magic
- if $ERROR_INFO.is_a?(ActionView::ActionViewError)
- @template.instance_variable_set(:@project, nil)
- @template.instance_variable_set(:@status, 500)
- @template.instance_variable_set(:@message, message)
- else
- @project = nil
- end
- rescue StandardError
- # bad luck
+ @project = nil # rubocop:disable Rails/HelperInstanceVariable
end
end
diff --git a/app/views/common/error.html.erb b/app/views/common/error.html.erb
index 85f38b27a71..ea265ef425a 100644
--- a/app/views/common/error.html.erb
+++ b/app/views/common/error.html.erb
@@ -29,4 +29,4 @@ See COPYRIGHT and LICENSE files for more details.
<%= call_hook(:view_common_error_details, { params: params, project: ((defined? @project) ? @project : nil) }) %>
-<% html_title h(@status) %>
+<% html_title h(status) %>