Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rescue Exceptions in dashboard widgets #3873

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/dashboard/app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ def render_widget(widget)
begin
render partial: "widgets/#{widget}"
rescue SyntaxError, StandardError => e
render partial: 'shared/widget_error', locals: { error: e, widget: widget.to_s }
render_error_widget(e, widget.to_s)
# rubocop:disable Lint/RescueException - because these can throw all sorts of errors.
rescue Exception => e
# rubocop:enable Lint/RescueException
render_error_widget(e, widget.to_s)
end
end

private

def render_error_widget(error, widget_name)
render(partial: 'shared/widget_error', locals: { error: error, widget: widget_name })
end

def default_dashboard_layout
if xdmod?
if pinned_apps? || motd?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%- require 'the_missing_gem' -%>
15 changes: 10 additions & 5 deletions apps/dashboard/test/integration/dashboard_layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,16 @@ def test_env
{
columns: [
{
width: 6,
width: 4,
widgets: 'this_widget_doesnt_exist'
},
{
width: 6,
width: 4,
widgets: 'syntax_error'
},
{
width: 4,
widgets: 'load_error'
}
]
}
Expand All @@ -263,12 +267,13 @@ def test_env
end

assert_select 'div.row', 1
assert_select 'div.row > div.col-md-6', 2
assert_select 'div.row > div.col-md-4', 3

error_widgets = css_select('div.row > div.col-md-6 > div.alert.alert-danger.card > div.card-body')
assert_equal 2, error_widgets.size
error_widgets = css_select('div.row > div.col-md-4 > div.alert.alert-danger.card > div.card-body')
assert_equal 3, error_widgets.size
assert_equal true, %r{Missing partial widgets/_this_widget_doesnt_exist}.match?(error_widgets[0].text)
assert_equal true, /undefined method `woops!'/.match?(error_widgets[1].text)
assert_equal true, /cannot load such file -- the_missing_gem/.match?(error_widgets[2].text)
end

test 'should render brand new widgets with shipped widgets' do
Expand Down
Loading