class Webgen::Error

This error class and its descendants are only used in webgen when user-visible errors need to be created. For example, when the format of the configuration is not valid. Use the built-in Ruby error classes for all other error situations!

Attributes

location[RW]

The location where the error happened (this can be set to a file name, a class name, …).

path[RW]

Contains the path name if the error is related to a specific source or destination path,

Public Class Methods

error_file(error) click to toggle source

Return the file name where the error occured.

   # File lib/webgen/error.rb
45 def self.error_file(error)
46   (error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/(?:^|\s)(.*?):(\d+)/).first.first
47 end
error_line(error) click to toggle source

Return the error line by inspecting the backtrace of the given error instance.

   # File lib/webgen/error.rb
40 def self.error_line(error)
41   (error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/:(\d+)/).first.first.to_i rescue nil
42 end
new(msg_or_error, location = nil, path = nil) click to toggle source

Create a new Error object.

If msg_or_error is a String, it is treated as the error message. If it is an exception, the exception is wrapped. The location parameter can be used to further describe where the error happened and the path parameter can be used to associate a source or destination path with the error.

Calls superclass method
   # File lib/webgen/error.rb
21 def initialize(msg_or_error, location = nil, path = nil)
22   if msg_or_error.kind_of?(String)
23     super(msg_or_error)
24   else
25     super(msg_or_error.message)
26     set_backtrace(msg_or_error.backtrace)
27   end
28   @location, @path = location, path.to_s
29 end