Exception: DeepCover::ProblemWithDiagnostic
- Inherits:
-
StandardError
- Object
- StandardError
- DeepCover::ProblemWithDiagnostic
- Defined in:
- lib/deep_cover/problem_with_diagnostic.rb
Instance Attribute Summary collapse
-
#covered_code ⇒ Object
readonly
Returns the value of attribute covered_code.
-
#line_range ⇒ Object
readonly
Returns the value of attribute line_range.
-
#original_exception ⇒ Object
readonly
Returns the value of attribute original_exception.
Instance Method Summary collapse
- #buffer ⇒ Object
- #diagnostic_information_lines ⇒ Object
-
#initialize(covered_code, line_range, original_exception = nil) ⇒ ProblemWithDiagnostic
constructor
A new instance of ProblemWithDiagnostic.
- #message ⇒ Object
- #source_lines(nb_context_line: 7) ⇒ Object
Constructor Details
#initialize(covered_code, line_range, original_exception = nil) ⇒ ProblemWithDiagnostic
Returns a new instance of ProblemWithDiagnostic.
7 8 9 10 11 12 13 14 15 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 7 def initialize(covered_code, line_range, original_exception = nil) @covered_code = covered_code if line_range.respond_to? :last_line @line_range = line_range.line..line_range.last_line else @line_range = line_range end @original_exception = original_exception end |
Instance Attribute Details
#covered_code ⇒ Object (readonly)
Returns the value of attribute covered_code.
5 6 7 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 5 def covered_code @covered_code end |
#line_range ⇒ Object (readonly)
Returns the value of attribute line_range.
5 6 7 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 5 def line_range @line_range end |
#original_exception ⇒ Object (readonly)
Returns the value of attribute original_exception.
5 6 7 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 5 def original_exception @original_exception end |
Instance Method Details
#buffer ⇒ Object
59 60 61 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 59 def buffer covered_code.buffer end |
#diagnostic_information_lines ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 33 def diagnostic_information_lines lines = [] lines << "Source file: #{covered_code.path}" lines << "Line numbers: #{line_range}" lines << 'Source lines around location:' lines.concat(source_lines.map { |line| " #{line}" }) if original_exception lines << 'Original exception:' lines << " #{original_exception.class}: #{original_exception.}" backtrace = Tools.truncate_backtrace(original_exception) lines.concat(backtrace.map { |line| " #{line}" }) end lines end |
#message ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 17 def msg = [] msg << 'You found a problem with DeepCover!' msg << 'Please open an issue at https://github.com/deep-cover/deep-cover/issues' msg << 'and include the following diagnostic information:' extra = begin diagnostic_information_lines.map { |line| "| #{line}" } rescue ProblemWithDiagnostic ["Oh no! We're in deep trouble!!!"] rescue Exception => e ["Oh no! Even diagnostics are failing: #{e}\n#{e.backtrace}"] end msg.concat(extra) msg.join("\n") end |
#source_lines(nb_context_line: 7) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/deep_cover/problem_with_diagnostic.rb', line 48 def source_lines(nb_context_line: 7) first_index = line_range.begin - nb_context_line - buffer.first_line first_index = 0 if first_index < 0 last_index = line_range.end + nb_context_line - buffer.first_line lines = buffer.source_lines[first_index..last_index] lines.pop if lines.last.empty? Tools.number_lines(lines, lineno: buffer.first_line + first_index, bad_linenos: line_range.to_a) end |