From f0cf354284f269bf0ac749cf6fc3c3f0073c2c59 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 23 Mar 2010 18:54:37 -0700 Subject: [PATCH 1/2] [Sass] List load paths when a file isn't found. Closes gh-108 --- doc-src/SASS_CHANGELOG.md | 3 +++ lib/sass/files.rb | 10 +++++++++- test/sass/engine_test.rb | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 35ef7dea..8a56ef4d 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -8,6 +8,9 @@ * Don't crash when `rake gems` is run in Rails with Sass installed. Thanks to [Florian Frank](http://github.com/flori). +* When raising a file-not-found error, + add a list of load paths that were checked. + ## 2.2.22 [Tagged on GitHub](http://github.com/nex3/haml/commit/2.2.22). diff --git a/lib/sass/files.rb b/lib/sass/files.rb index fde24dbd..0f3c508c 100644 --- a/lib/sass/files.rb +++ b/lib/sass/files.rb @@ -85,7 +85,15 @@ If you really need #{filename}.css, import it explicitly. END return filename + '.css' end - raise SyntaxError.new("File to import not found or unreadable: #{original_filename}.", @line) + + message = "File to import not found or unreadable: #{original_filename}.\n" + if load_paths.size == 1 + message << "Load path: #{load_paths.first}" + else + message << "Load paths:\n " << load_paths.join("\n ") + end + + raise SyntaxError.new(message, @line) end private diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb index 197289e4..cdebeeeb 100755 --- a/test/sass/engine_test.rb +++ b/test/sass/engine_test.rb @@ -55,7 +55,12 @@ MSG "a," => "Rules can\'t end in commas.", "a,\n!b = 1" => ["Rules can\'t end in commas.", 1], "!a = b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.", - "@import foo.sass" => "File to import not found or unreadable: foo.sass.", + "@import foo.sass" => < "Illegal nesting: Nothing may be nested beneath import directives.", "foo\n @import templates/basic" => "Import directives may only be used at the root of a document.", "foo\n @import #{File.dirname(__FILE__)}/templates/basic" => "Import directives may only be used at the root of a document.", From 0a52f55d3e1396f2575b00643f6c5ca574543a58 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 23 Mar 2010 20:06:28 -0700 Subject: [PATCH 2/2] [Sass] Print exceptions properly when they're raised in cached files. --- doc-src/SASS_CHANGELOG.md | 4 ++++ lib/sass/plugin.rb | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 8a56ef4d..175ffd92 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -11,6 +11,10 @@ * When raising a file-not-found error, add a list of load paths that were checked. +* If an import isn't found for a cached Sass file and the + {file:SASS_REFERENCE.md#full_exception `:full_exception option`} is enabled, + print the full exception rather than raising it. + ## 2.2.22 [Tagged on GitHub](http://github.com/nex3/haml/commit/2.2.22). diff --git a/lib/sass/plugin.rb b/lib/sass/plugin.rb index 947725ef..5cbcf2fd 100644 --- a/lib/sass/plugin.rb +++ b/lib/sass/plugin.rb @@ -204,8 +204,13 @@ END def dependency_updated?(css_mtime) lambda do |dep| - File.mtime(dep) > css_mtime || - dependencies(dep).any?(&dependency_updated?(css_mtime)) + begin + File.mtime(dep) > css_mtime || + dependencies(dep).any?(&dependency_updated?(css_mtime)) + rescue Sass::SyntaxError + # If there's an error finding depenencies, default to recompiling. + true + end end end