Sha256: c297349e36e462bf7de94f50351105f29faf8c7d2d6d4eab14e3569ca8828889

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

module Locomotive
  module Wagon

    class DefaultException < ::Exception

      def initialize(message = nil, parent_exception = nil)
        self.log_backtrace(parent_exception) if parent_exception

        super(message)
      end

      protected

      def log_backtrace(parent_exception)
        full_error_message = "#{parent_exception.message}\n\t"
        full_error_message += parent_exception.backtrace.join("\n\t")
        full_error_message += "\n\n"
        Locomotive::Wagon::Logger.fatal full_error_message
      end

    end

    class RendererException < DefaultException

      attr_accessor :name, :template, :liquid_context

      def initialize(exception, name, template, liquid_context)
        self.name, self.template, self.liquid_context = name, template, liquid_context

        self.log_page_into_backtrace(exception)

        super(exception.message)

        self.set_backtrace(exception.backtrace)
      end

      def log_page_into_backtrace(exception)
        line = self.template.line_offset
        line += (exception.respond_to?(:line) ? exception.line || 0 : 0) + 1

        message = "#{self.template.filepath}:#{line}:in `#{self.name}'"

        Locomotive::Wagon::Logger.fatal "[ERROR] #{exception.message} - #{message}\n".red

        exception.backtrace.unshift message
      end

    end

    class MounterException < DefaultException
    end

    class GeneratorException < DefaultException

      def log_backtrace(parent_exception)
        # Logger not initialized at this step
      end

    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.5.8 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.7 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.6 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.5 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.4 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.3 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.2 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.1 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.0 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.5.0.rc1 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.4.0 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.3.3 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.3.2 lib/locomotive/wagon/exceptions.rb
locomotivecms_wagon-1.3.1 lib/locomotive/wagon/exceptions.rb