Skip to content

FIX: Catch postcss errors correctly for theme fields #32800

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

Merged
merged 1 commit into from
May 19, 2025
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
4 changes: 2 additions & 2 deletions app/models/theme_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def compiled_css(prepended_scss)
css, _source_map =
begin
compile_scss(prepended_scss)
rescue SassC::SyntaxError => e
rescue SassC::SyntaxError, DiscourseJsProcessor::TranspileError => e
# We don't want to raise a blocking error here
# admin theme editor or discourse_theme CLI will show it nonetheless
Rails.logger.error "SCSS compilation error: #{e.message}"
Expand All @@ -568,7 +568,7 @@ def ensure_scss_compiles!
else
self.error = nil unless error.nil?
end
rescue SassC::SyntaxError, SassC::NotRenderedError => e
rescue SassC::SyntaxError, SassC::NotRenderedError, DiscourseJsProcessor::TranspileError => e
self.error = e.message unless self.destroyed?
end
self.compiler_version = Theme.compiler_version
Expand Down
8 changes: 8 additions & 0 deletions spec/models/theme_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@
theme.save!
expect(field.reload.error).to include('Error: expected "}"')

theme.set_field(target: :common, name: :scss, value: <<~SCSS)
body {
color: unquote("https://example.com/this-is-a-mistake");
}
SCSS
theme.save!
expect(field.reload.error).to include("CssSyntaxError: Missed semicolon")

theme.set_field(target: :common, name: :scss, value: "@import 'missingfile';")
theme.save!
expect(field.reload.error).to include("Error: Can't find stylesheet to import.")
Expand Down
Loading