Module: Bridgetown::Errors

Defined in:
bridgetown-core/lib/bridgetown-core/errors.rb

Constant Summary collapse

FatalException =
Class.new(::RuntimeError)
DropMutationException =
Class.new(FatalException)
InvalidPermalinkError =
Class.new(FatalException)
InvalidYAMLFrontMatterError =
Class.new(FatalException)
MissingDependencyException =
Class.new(FatalException)
InvalidDateError =
Class.new(FatalException)
InvalidPostNameError =
Class.new(FatalException)
PostURLError =
Class.new(FatalException)
InvalidURLError =
Class.new(FatalException)
InvalidConfigurationError =
Class.new(FatalException)

Class Method Summary collapse

Class Method Details

rubocop:todo Metrics



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'bridgetown-core/lib/bridgetown-core/errors.rb', line 18

def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:todo Metrics
  logger.error "Exception raised:", exc.class.to_s.bold
  logger.error exc.message.reset_ansi

  build_errors_file = Bridgetown.build_errors_path if !server && Bridgetown::Current.site
  build_errors_data = "#{exc.class}: #{exc.message}"

  trace_args = ["-t", "--trace"]
  print_trace_msg = true
  traces = if trace || ARGV.find { |arg| trace_args.include?(arg) }
             print_trace_msg = false
             exc.backtrace
           else
             exc.backtrace.grep_v(%r!bridgetown-core.+method_missing!)[0..4]
           end
  traces.each_with_index do |backtrace_line, index|
    logger.error "#{index + 1}:", backtrace_line.reset_ansi
    build_errors_data << "\n#{backtrace_line}" if index < 2
  end

  if build_errors_file
    FileUtils.mkdir_p(File.dirname(build_errors_file))
    File.write(build_errors_file, build_errors_data, mode: "w")
  end

  return unless print_trace_msg

  logger.warn "Backtrace:", "Use the --trace option for complete information."
end