A platform for community discussion. Free, open, simple.
DEV: Improve color-definition stylesheet failure mode (#31858)
David Taylor06b7b4981ffd
diff --git a/lib/stylesheet/manager/builder.rb b/lib/stylesheet/manager/builder.rbindex ecffb7cbb93..f81be1cf1a0 100644--- a/lib/stylesheet/manager/builder.rb+++ b/lib/stylesheet/manager/builder.rb@@ -53,10 +53,10 @@ class Stylesheet::Manager::Builderif Stylesheet::Importer::THEME_TARGETS.include?(@target.to_s)# no special errors for theme, handled in theme editor["", nil]- elsif @target.to_s == Stylesheet::Manager::COLOR_SCHEME_STYLESHEET+ elsif @target.to_s == Stylesheet::Manager::COLOR_SCHEME_STYLESHEET && Rails.env.production?# log error but do not crash for errors in color definitions SCSSRails.logger.error "SCSS compilation error: #{e.message}"- ["", nil]+ ["/* SCSS compilation error: #{e.message} */", nil]elseraise Discourse::ScssError, e.messageenddiff --git a/spec/lib/stylesheet/manager_spec.rb b/spec/lib/stylesheet/manager_spec.rbindex a304452fa5c..d17f0db7ce7 100644--- a/spec/lib/stylesheet/manager_spec.rb+++ b/spec/lib/stylesheet/manager_spec.rb@@ -854,7 +854,7 @@ RSpec.describe Stylesheet::Manager doexpect(stylesheet).to include("--child-definition: #fff")end- it "fails gracefully for broken SCSS" do+ it "fails gracefully in production for broken SCSS" doscss = "$test: $missing-var;"theme.set_field(target: :common, name: "color_definitions", value: scss)theme.save!@@ -869,7 +869,12 @@ RSpec.describe Stylesheet::Manager domanager: manager,)- expect { stylesheet.compile }.not_to raise_error+ expect { stylesheet.compile }.to raise_error(Discourse::ScssError)++ Rails.env.stubs(:production?).returns(true)+ expect(stylesheet.compile).to include(+ "/* SCSS compilation error: Error: Undefined variable",+ )endit "child theme SCSS includes the default theme's color scheme variables" do