From eeacd205ea4523ec396c702152d10f3a2f061d29 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 24 Dec 2009 11:30:27 -0800 Subject: [PATCH] [Sass] Give a reasonable error message when something goes wrong loading Sass. --- lib/haml/exec.rb | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 7275646c..bfefae62 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -244,26 +244,29 @@ END end super - input = @options[:input] - output = @options[:output] - tree = - if input.is_a?(File) && !@options[:check_syntax] - ::Sass::Files.tree_for(input.path, @options[:for_engine]) - else - # We don't need to do any special handling of @options[:check_syntax] here, - # because the Sass syntax checking happens alongside evaluation - # and evaluation doesn't actually evaluate any code anyway. - ::Sass::Engine.new(input.read(), @options[:for_engine]).to_tree - end + begin + input = @options[:input] + output = @options[:output] - input.close() if input.is_a?(File) + tree = + if input.is_a?(File) && !@options[:check_syntax] + ::Sass::Files.tree_for(input.path, @options[:for_engine]) + else + # We don't need to do any special handling of @options[:check_syntax] here, + # because the Sass syntax checking happens alongside evaluation + # and evaluation doesn't actually evaluate any code anyway. + ::Sass::Engine.new(input.read(), @options[:for_engine]).to_tree + end - output.write(tree.render) - output.close() if output.is_a? File - rescue ::Sass::SyntaxError => e - raise e if @options[:trace] - raise "Syntax error on line #{get_line e}: #{e.message}" + input.close() if input.is_a?(File) + + output.write(tree.render) + output.close() if output.is_a? File + rescue ::Sass::SyntaxError => e + raise e if @options[:trace] + raise "Syntax error on line #{get_line e}: #{e.message}" + end end end