class Omnibus::Fetcher::ErrorReporter
Given an error and a fetcher that generated the error, print a formatted report of the error and stacktrace, along with fetcher details to stderr.
@note Does not rethrow the error; that must currently be done manually.
@todo Since this is always called from within a fetcher, and
since the fetcher always passes itself in in the {#initialize} method, this really ought to be encapsulated in a method call on {Omnibus::Fetcher}.
@todo Also, since we always ‘raise’ after calling {#explain}, we
should just go ahead and exit from here. No need to raise, since we're already outputting the real error and stacktrace here.
Public Class Methods
# File lib/omnibus/fetcher.rb, line 47 def initialize(error, fetcher) @error, @fetcher = error, fetcher end
Public Instance Methods
@todo Why not just make an attribute for error?
@todo And for that matter, why not make an attribute for the
fetcher as well? Or why not just use `@error` like we use `@fetcher`?
# File lib/omnibus/fetcher.rb, line 56 def e @error end
@todo If {Omnibus::Fetcher#description} is meant to show
parameters (presumably the kind of fetcher and the software it is fetching?),
# File lib/omnibus/fetcher.rb, line 63 def explain(why) $stderr.puts "* " * 40 $stderr.puts why $stderr.puts "Fetcher params:" $stderr.puts indent(@fetcher.description, 2) $stderr.puts "Exception:" $stderr.puts indent("#{e.class}: #{e.message.strip}", 2) Array(e.backtrace).each {|l| $stderr.puts indent(l, 4) } $stderr.puts "* " * 40 end
Private Instance Methods
Indent each line of a string with ‘n` spaces.
Splits the string at ‘n` characters and then pads the left side with `n` spaces. Rejoins them all again with `n`.
@param string [String] the string to indent @param n [Fixnum] the number of “ ” characters to indent each line. @return [String]
# File lib/omnibus/fetcher.rb, line 84 def indent(string, n) string.split("\n").map {|l| " ".rjust(n) << l }.join("\n") end