Class: Rosette::Core::PrintingErrorReporter
- Inherits:
-
ErrorReporter
- Object
- ErrorReporter
- Rosette::Core::PrintingErrorReporter
- Defined in:
- lib/rosette/core/error_reporters/printing_error_reporter.rb
Overview
Prints errors.
Instance Attribute Summary collapse
-
#print_stack_trace ⇒ Boolean
(also: #print_stack_trace?)
readonly
Whether or not to print a stack trace along with the error message.
-
#stream ⇒ #write
readonly
A stream-like object to print errors to.
Instance Method Summary collapse
-
#initialize(stream, options = {}) ⇒ PrintingErrorReporter
constructor
Creates a new error reporter.
-
#report_error(error, options = {}) ⇒ void
Print an error.
-
#report_warning(error, options = {}) ⇒ void
Print a warning.
Methods inherited from ErrorReporter
Constructor Details
#initialize(stream, options = {}) ⇒ PrintingErrorReporter
Creates a new error reporter.
23 24 25 26 |
# File 'lib/rosette/core/error_reporters/printing_error_reporter.rb', line 23 def initialize(stream, = {}) @stream = stream @print_stack_trace = .fetch(:print_stack_trace, false) end |
Instance Attribute Details
#print_stack_trace ⇒ Boolean (readonly) Also known as: print_stack_trace?
Returns whether or not to print a stack trace along with the error message.
13 14 15 16 17 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 47 48 49 50 51 52 53 54 55 |
# File 'lib/rosette/core/error_reporters/printing_error_reporter.rb', line 13 class PrintingErrorReporter < ErrorReporter attr_reader :stream, :print_stack_trace alias :print_stack_trace? :print_stack_trace # Creates a new error reporter. # # @param [#write] stream The stream-like object to print errors to. # @param [Hash] options A hash of options. Can contain: # * +print_stack_trace+: A boolean value indicating whether or not # a stack trace should be printed alongside the error message. def initialize(stream, = {}) @stream = stream @print_stack_trace = .fetch(:print_stack_trace, false) end # Print an error. # # @param [Exception] error The error to print. # @param [Hash] options A hash of associated options (will also be # printed) # @return [void] def report_error(error, = {}) stream.write("#{error.}\n") if print_stack_trace? Array(error.backtrace).each do |line| stream.write("#{line}\n") end stream.write(.inspect) end end # Print a warning. Warnings are treated the same as errors. # # @param [Exception] error The error to print. # @param [Hash] options A hash of associated options (will also be # printed) # @return [void] def report_warning(error, = {}) report_error(error, ) end end |
#stream ⇒ #write (readonly)
Returns a stream-like object to print errors to.
13 14 15 16 17 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 47 48 49 50 51 52 53 54 55 |
# File 'lib/rosette/core/error_reporters/printing_error_reporter.rb', line 13 class PrintingErrorReporter < ErrorReporter attr_reader :stream, :print_stack_trace alias :print_stack_trace? :print_stack_trace # Creates a new error reporter. # # @param [#write] stream The stream-like object to print errors to. # @param [Hash] options A hash of options. Can contain: # * +print_stack_trace+: A boolean value indicating whether or not # a stack trace should be printed alongside the error message. def initialize(stream, = {}) @stream = stream @print_stack_trace = .fetch(:print_stack_trace, false) end # Print an error. # # @param [Exception] error The error to print. # @param [Hash] options A hash of associated options (will also be # printed) # @return [void] def report_error(error, = {}) stream.write("#{error.}\n") if print_stack_trace? Array(error.backtrace).each do |line| stream.write("#{line}\n") end stream.write(.inspect) end end # Print a warning. Warnings are treated the same as errors. # # @param [Exception] error The error to print. # @param [Hash] options A hash of associated options (will also be # printed) # @return [void] def report_warning(error, = {}) report_error(error, ) end end |
Instance Method Details
#report_error(error, options = {}) ⇒ void
This method returns an undefined value.
Print an error.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rosette/core/error_reporters/printing_error_reporter.rb', line 34 def report_error(error, = {}) stream.write("#{error.}\n") if print_stack_trace? Array(error.backtrace).each do |line| stream.write("#{line}\n") end stream.write(.inspect) end end |
#report_warning(error, options = {}) ⇒ void
This method returns an undefined value.
Print a warning. Warnings are treated the same as errors.
52 53 54 |
# File 'lib/rosette/core/error_reporters/printing_error_reporter.rb', line 52 def report_warning(error, = {}) report_error(error, ) end |