Skip to content
Browse files

Annotate exceptions raised in Context#evaluate with source file and l…

…ine number
  • Loading branch information...
1 parent 63e54d0 commit 42501353ee0349e7b7b99dd8eb0a5328ad77f333 @sstephenson sstephenson committed
Showing with 14 additions and 3 deletions.
  1. +13 −2 lib/sprockets/context.rb
  2. +1 −1 test/test_server.rb
View
15 lib/sprockets/context.rb
@@ -76,8 +76,12 @@ def evaluate(filename, options = {})
attributes.engines.reverse
engines.inject(data) do |result, engine|
- template = engine.new(pathname.to_s) { result }
- template.render(self, {})
+ begin
+ template = engine.new(pathname.to_s) { result }
+ template.render(self, {})
+ rescue Exception => e
+ raise e.class, annotate_error_message(e.message)
+ end
end
end
@@ -97,5 +101,12 @@ def require_asset(path)
pathname
end
+
+ private
+ def annotate_error_message(message)
+ annotation = "in #{@pathname.to_s}"
+ annotation << ":#{@__LINE__}" if @__LINE__
+ "#{message}\n#{annotation}"
+ end
end
end
View
2 test/test_server.rb
@@ -160,7 +160,7 @@ def app
test "re-throw exception in browser if JS require is missing" do
get "/javascripts/missing_require.js"
assert_equal 500, last_response.status
- assert_equal "throw Error(\"Sprockets::FileNotFound: couldn't find file 'notfound'\")", last_response.body
+ assert_equal "throw Error(\"Sprockets::FileNotFound: couldn't find file 'notfound'\\nin #{fixture_path("server/vendor/javascripts/missing_require.js")}:1\")", last_response.body
end
test "illegal require outside load path" do

0 comments on commit 4250135

Please sign in to comment.
Something went wrong with that request. Please try again.