Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def print_error(error)
  $stderr.puts

  # Header
  $stderr.puts '+--- /!\ ERROR /!\ -------------------------------------------+'
  $stderr.puts '| An exception occured while compiling the site. If you think |'
  $stderr.puts '| this is a bug in nanoc, please do report it at              |'
  $stderr.puts '| <http://projects.stoneship.org/trac/nanoc/newticket> --     |'
  $stderr.puts '| thanks in advance!                                          |'
  $stderr.puts '+-------------------------------------------------------------+'

  # Exception
  $stderr.puts
  $stderr.puts '=== MESSAGE:'
  $stderr.puts
  $stderr.puts "#{error.class}: #{error.message}"

  # Compilation stack
  $stderr.puts
  $stderr.puts '=== COMPILATION STACK:'
  $stderr.puts
  if ((@base.site && @base.site.compiler.stack) || []).empty?
    $stderr.puts "  (empty)"
  else
    @base.site.compiler.stack.reverse.each do |obj|
      if obj.is_a?(Nanoc3::ItemRep)
        $stderr.puts "  - [item]   #{obj.item.identifier} (rep #{obj.name})"
      else # layout
        $stderr.puts "  - [layout] #{obj.identifier}"
      end
    end
  end

  # Backtrace
  require 'enumerator'
  $stderr.puts
  $stderr.puts '=== BACKTRACE:'
  $stderr.puts
  $stderr.puts error.backtrace.to_enum(:each_with_index).map { |item, index| "  #{index}. #{item}" }.join("\n")
end