From 7f60c9d8a11f2b67093325dc440743d3d39c0375 Mon Sep 17 00:00:00 2001 From: Breno Gazzola Date: Thu, 25 Nov 2021 08:39:33 -0300 Subject: [PATCH] Warn on missing asset in compiler (#31) * Warn on missing asset in compiler * Clarify warning Co-authored-by: David Heinemeier Hansson --- lib/propshaft/compilers/css_asset_urls.rb | 7 ++++--- test/propshaft/compilers/css_asset_urls_test.rb | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/propshaft/compilers/css_asset_urls.rb b/lib/propshaft/compilers/css_asset_urls.rb index 20cb68b..251b7b6 100644 --- a/lib/propshaft/compilers/css_asset_urls.rb +++ b/lib/propshaft/compilers/css_asset_urls.rb @@ -11,7 +11,7 @@ def initialize(assembly) end def compile(logical_path, input) - input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(logical_path.dirname, $1) } + input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(logical_path.dirname, $1), logical_path, $1 } end private @@ -25,11 +25,12 @@ def resolve_path(directory, filename) end end - def asset_url(resolved_path) + def asset_url(resolved_path, logical_path, pattern) if asset = assembly.load_path.find(resolved_path) %[url("#{assembly.config.prefix}/#{asset.digested_path}")] else - raise Propshaft::MissingAssetError.new(resolved_path) + Propshaft.logger.warn "Unable to resolve '#{pattern}' for missing asset '#{resolved_path}' in #{logical_path}" + %[url("#{pattern}")] end end end diff --git a/test/propshaft/compilers/css_asset_urls_test.rb b/test/propshaft/compilers/css_asset_urls_test.rb index 017447e..66ca969 100644 --- a/test/propshaft/compilers/css_asset_urls_test.rb +++ b/test/propshaft/compilers/css_asset_urls_test.rb @@ -91,9 +91,8 @@ class Propshaft::Compilers::CssAssetUrlsTest < ActiveSupport::TestCase end test "missing asset" do - assert_raise Propshaft::MissingAssetError do - compile_asset_with_content(%({ background: url(missing.jpg); })) - end + compiled = compile_asset_with_content(%({ background: url("file-not-found.jpg"); })) + assert_match /{ background: url\("file-not-found.jpg"\); }/, compiled end private