Skip to content

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.rb
index ecffb7cbb93..f81be1cf1a0 100644
--- a/lib/stylesheet/manager/builder.rb
+++ b/lib/stylesheet/manager/builder.rb
@@ -53,10 +53,10 @@ class Stylesheet::Manager::Builder
if 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 SCSS
Rails.logger.error "SCSS compilation error: #{e.message}"
- ["", nil]
+ ["/* SCSS compilation error: #{e.message} */", nil]
else
raise Discourse::ScssError, e.message
end
diff --git a/spec/lib/stylesheet/manager_spec.rb b/spec/lib/stylesheet/manager_spec.rb
index 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 do
expect(stylesheet).to include("--child-definition: #fff")
end
- it "fails gracefully for broken SCSS" do
+ it "fails gracefully in production for broken SCSS" do
scss = "$test: $missing-var;"
theme.set_field(target: :common, name: "color_definitions", value: scss)
theme.save!
@@ -869,7 +869,12 @@ RSpec.describe Stylesheet::Manager do
manager: 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",
+ )
end
it "child theme SCSS includes the default theme's color scheme variables" do