Skip to content
This repository

Better reporting of Liquid errors #624

Merged
merged 1 commit into from over 1 year ago

4 participants

Will Brady Jamie Phelps Alexander Dymo Tom Preston-Werner
Will Brady

The current issue is if you have a malformed Liquid call, Jekyll builds the site just fine but includes the Liquid exception as text on your page. You would have to stumble upon a page with an error on it to realize your code is wrong. If Liquid parsing/rendering fails, Jekyll should fail building as well (and alert you to what happened).

The solution is to call .render! rather than simply .render on Liquid templates. I do that here in the do_layout method of Convertible. I also add a stack trace dump and abort building Jekyll.

Jamie Phelps

Please merge this in. I am using Jekyll for a project now and I want to have a pre-receive hook on my deploy git remote that runs jekyll and aborts the receive if there are any errors. Having raw liquid spewing out into the pages when it's entirely preventable is definitely not desirable.

Alexander Dymo

I also support this. Rendering errors should not be hidden from developers. This is especially important when custom tags are used.

Tom Preston-Werner mojombo merged commit 336ea66 into from
Tom Preston-Werner mojombo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 14, 2012
Better error reporting on Liquid exceptions 336ea66
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 10 additions and 2 deletions. Show diff stats Hide diff stats

  1. 12  lib/jekyll/convertible.rb
12  lib/jekyll/convertible.rb
@@ -76,9 +76,13 @@ def do_layout(payload, layouts)
76 76
       payload["pygments_suffix"] = converter.pygments_suffix
77 77
 
78 78
       begin
79  
-        self.content = Liquid::Template.parse(self.content).render(payload, info)
  79
+        self.content = Liquid::Template.parse(self.content).render!(payload, info)
80 80
       rescue => e
81 81
         puts "Liquid Exception: #{e.message} in #{self.name}"
  82
+        e.backtrace.each do |backtrace|
  83
+          puts backtrace
  84
+        end
  85
+        abort("Build Failed")
82 86
       end
83 87
 
84 88
       self.transform
@@ -94,9 +98,13 @@ def do_layout(payload, layouts)
94 98
         payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
95 99
 
96 100
         begin
97  
-          self.output = Liquid::Template.parse(layout.content).render(payload, info)
  101
+          self.output = Liquid::Template.parse(layout.content).render!(payload, info)
98 102
         rescue => e
99 103
           puts "Liquid Exception: #{e.message} in #{self.data["layout"]}"
  104
+          e.backtrace.each do |backtrace|
  105
+            puts backtrace
  106
+          end
  107
+          abort("Build Failed")
100 108
         end
101 109
 
102 110
         if layout = layouts[layout.data["layout"]]
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.