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
The location where the error happened (this can be set to a file name, a class name, …).
Contains the path name if the error is related to a specific source or destination path,
Public Class Methods
Return the file name where the error occured.
# File lib/webgen/error.rb, line 45 def self.error_file(error) (error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/(?:^|\s)(.*?):(\d+)/).first.first end
Return the error line by inspecting the backtrace of the given
error instance.
# File lib/webgen/error.rb, line 40 def self.error_line(error) (error.is_a?(::SyntaxError) ? error.message : error.backtrace[0]).scan(/:(\d+)/).first.first.to_i rescue nil end
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.
# File lib/webgen/error.rb, line 21 def initialize(msg_or_error, location = nil, path = nil) if msg_or_error.kind_of?(String) super(msg_or_error) else super(msg_or_error.message) set_backtrace(msg_or_error.backtrace) end @location, @path = location, path.to_s end