set `LiquidError#template_name` for errors in included file (#6206)
Merge pull request 6206
This commit is contained in:
		
							parent
							
								
									73419cb374
								
							
						
					
					
						commit
						cc1cb8150a
					
				|  | @ -12,14 +12,23 @@ Feature: Rendering | ||||||
|     Then  I should get a non-zero exit-status |     Then  I should get a non-zero exit-status | ||||||
|     And   I should see "Liquid Exception" in the build output |     And   I should see "Liquid Exception" in the build output | ||||||
| 
 | 
 | ||||||
|   Scenario: When receiving bad Liquid in included file |   Scenario: When receiving a liquid syntax error in included file | ||||||
|     Given I have a _includes directory |     Given I have a _includes directory | ||||||
|     And   I have a "_includes/invalid.html" file that contains "{% INVALID %}" |     And   I have a "_includes/invalid.html" file that contains "{% INVALID %}" | ||||||
|     And   I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}" |     And   I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}" | ||||||
|     And   I have a simple layout that contains "{{ content }}" |     And   I have a simple layout that contains "{{ content }}" | ||||||
|     When  I run jekyll build |     When  I run jekyll build | ||||||
|     Then  I should get a non-zero exit-status |     Then  I should get a non-zero exit-status | ||||||
|     And   I should see "Liquid Exception.*Unknown tag 'INVALID' in.*_includes/invalid\.html" in the build output |     And   I should see "Liquid Exception: Liquid syntax error \(.+/invalid\.html line 1\): Unknown tag 'INVALID' included in index\.html" in the build output | ||||||
|  | 
 | ||||||
|  |   Scenario: When receiving a generic liquid error in included file | ||||||
|  |     Given I have a _includes directory | ||||||
|  |     And   I have a "_includes/invalid.html" file that contains "{{ site.title | prepend 'Prepended Text' }}" | ||||||
|  |     And   I have a "index.html" page with layout "simple" that contains "{% include invalid.html %}" | ||||||
|  |     And   I have a simple layout that contains "{{ content }}" | ||||||
|  |     When  I run jekyll build | ||||||
|  |     Then  I should get a non-zero exit-status | ||||||
|  |     And   I should see "Liquid Exception: Liquid error \(.+/_includes/invalid\.html line 1\): wrong number of arguments (\(given 1, expected 2\)|\(1 for 2\)) included in index\.html" in the build output | ||||||
| 
 | 
 | ||||||
|   Scenario: Render Liquid and place in layout |   Scenario: Render Liquid and place in layout | ||||||
|     Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!" |     Given I have a "index.html" page with layout "simple" that contains "Hi there, Jekyll {{ jekyll.environment }}!" | ||||||
|  |  | ||||||
|  | @ -43,9 +43,6 @@ module Jekyll | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def self.format_error(e, path) |     def self.format_error(e, path) | ||||||
|       if e.is_a? Tags::IncludeTagError |  | ||||||
|         return "#{e.message} in #{e.path}, included in #{path}" |  | ||||||
|       end |  | ||||||
|       "#{e.message} in #{path}" |       "#{e.message} in #{path}" | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|  | @ -136,7 +136,13 @@ eos | ||||||
| 
 | 
 | ||||||
|         context.stack do |         context.stack do | ||||||
|           context["include"] = parse_params(context) if @params |           context["include"] = parse_params(context) if @params | ||||||
|           partial.render!(context) |           begin | ||||||
|  |             partial.render!(context) | ||||||
|  |           rescue Liquid::Error => e | ||||||
|  |             e.template_name = path | ||||||
|  |             e.markup_context = "included " if e.markup_context.nil? | ||||||
|  |             raise e | ||||||
|  |           end | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  | @ -161,8 +167,10 @@ eos | ||||||
|             .file(path) |             .file(path) | ||||||
|           begin |           begin | ||||||
|             cached_partial[path] = unparsed_file.parse(read_file(path, context)) |             cached_partial[path] = unparsed_file.parse(read_file(path, context)) | ||||||
|           rescue Liquid::SyntaxError => ex |           rescue Liquid::Error => e | ||||||
|             raise IncludeTagError.new(ex.message, path) |             e.template_name = path | ||||||
|  |             e.markup_context = "included " if e.markup_context.nil? | ||||||
|  |             raise e | ||||||
|           end |           end | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue