aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template/error.rb
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-03-28 14:53:22 -0400
committerGitHub <noreply@github.com>2019-03-28 14:53:22 -0400
commite3f5f1c936869b81b01835adc9c683e058edfeaf (patch)
tree7cc31fadaa654951237faf843015be6b070ae382 /actionview/lib/action_view/template/error.rb
parent78ace9cd080e626feb89ffb9e4142f0b672a53b3 (diff)
parent07804d4759726da04020834502d37a8f4ac97a8f (diff)
downloadrails-e3f5f1c936869b81b01835adc9c683e058edfeaf.tar.gz
rails-e3f5f1c936869b81b01835adc9c683e058edfeaf.tar.bz2
rails-e3f5f1c936869b81b01835adc9c683e058edfeaf.zip
Merge pull request #35308 from erose/better-error-reporting-for-syntax-errors-in-templates
Display a more helpful error message when an ERB template has a Ruby syntax error.
Diffstat (limited to 'actionview/lib/action_view/template/error.rb')
-rw-r--r--actionview/lib/action_view/template/error.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/actionview/lib/action_view/template/error.rb b/actionview/lib/action_view/template/error.rb
index 4e3c02e05e..ff01e4cd83 100644
--- a/actionview/lib/action_view/template/error.rb
+++ b/actionview/lib/action_view/template/error.rb
@@ -138,4 +138,24 @@ module ActionView
end
TemplateError = Template::Error
+
+ class SyntaxErrorInTemplate < TemplateError #:nodoc
+ def initialize(template, offending_code_string)
+ @offending_code_string = offending_code_string
+ super(template)
+ end
+
+ def message
+ <<~MESSAGE
+ Encountered a syntax error while rendering template: check #{@offending_code_string}
+ MESSAGE
+ end
+
+ def annoted_source_code
+ @offending_code_string.split("\n").map.with_index(1) { |line, index|
+ indentation = " " * 4
+ "#{index}:#{indentation}#{line}"
+ }
+ end
+ end
end