Commit 615c90c6 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Make sure we don't read known sprites in prod

node_modules is cleaned up in Omnibus so this was causing errors
on all pages that rendered an icon
parent 3e6414b7
...@@ -42,7 +42,7 @@ module IconsHelper ...@@ -42,7 +42,7 @@ module IconsHelper
end end
def sprite_icon(icon_name, size: nil, css_class: nil) def sprite_icon(icon_name, size: nil, css_class: nil)
unless known_sprites.include?(icon_name) if known_sprites&.exclude?(icon_name)
exception = ArgumentError.new("#{icon_name} is not a known icon in @gitlab-org/gitlab-svg") exception = ArgumentError.new("#{icon_name} is not a known icon in @gitlab-org/gitlab-svg")
Gitlab::Sentry.track_and_raise_for_dev_exception(exception) Gitlab::Sentry.track_and_raise_for_dev_exception(exception)
end end
...@@ -156,6 +156,8 @@ module IconsHelper ...@@ -156,6 +156,8 @@ module IconsHelper
private private
def known_sprites def known_sprites
return if Rails.env.production?
@known_sprites ||= JSON.parse(File.read(Rails.root.join('node_modules/@gitlab/svgs/dist/icons.json')))['icons'] @known_sprites ||= JSON.parse(File.read(Rails.root.join('node_modules/@gitlab/svgs/dist/icons.json')))['icons']
end end
end end
...@@ -76,6 +76,8 @@ describe IconsHelper do ...@@ -76,6 +76,8 @@ describe IconsHelper do
it 'does not raise in production mode' do it 'does not raise in production mode' do
stub_rails_env('production') stub_rails_env('production')
expect(File).not_to receive(:read)
expect { sprite_icon(non_existing) }.not_to raise_error expect { sprite_icon(non_existing) }.not_to raise_error
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment