Exception: Danger::DSLError
- Inherits:
-
StandardError
- Object
- StandardError
- Danger::DSLError
- Defined in:
- lib/danger/danger_core/standard_error.rb
Overview
Wraps an exception raised by a DSL file in order to show to the user the contents of the line that raised the exception.
Instance Attribute Summary collapse
-
#backtrace ⇒ Exception
readonly
The backtrace of the exception raised by the evaluation of the dsl file.
-
#description ⇒ String
readonly
The description that should be presented to the user.
-
#dsl_path ⇒ String
readonly
The path of the dsl file that raised the exception.
Instance Method Summary collapse
-
#contents ⇒ String
The contents of the DSL that cause the exception to be raised.
-
#initialize(description, dsl_path, backtrace, contents = nil) ⇒ DSLError
constructor
A new instance of DSLError.
-
#message ⇒ String
The message of the exception reports the content of podspec for the line that generated the original exception.
- #to_markdown ⇒ Object
Constructor Details
#initialize(description, dsl_path, backtrace, contents = nil) ⇒ DSLError
Returns a new instance of DSLError.
29 30 31 32 33 34 |
# File 'lib/danger/danger_core/standard_error.rb', line 29 def initialize(description, dsl_path, backtrace, contents = nil) @description = description @dsl_path = dsl_path @backtrace = backtrace @contents = contents end |
Instance Attribute Details
#backtrace ⇒ Exception (readonly)
Returns the backtrace of the exception raised by the evaluation of the dsl file.
24 25 26 |
# File 'lib/danger/danger_core/standard_error.rb', line 24 def backtrace @backtrace end |
#description ⇒ String (readonly)
Returns the description that should be presented to the user.
15 16 17 |
# File 'lib/danger/danger_core/standard_error.rb', line 15 def description @description end |
#dsl_path ⇒ String (readonly)
Returns the path of the dsl file that raised the exception.
19 20 21 |
# File 'lib/danger/danger_core/standard_error.rb', line 19 def dsl_path @dsl_path end |
Instance Method Details
#contents ⇒ String
Returns the contents of the DSL that cause the exception to be raised.
39 40 41 |
# File 'lib/danger/danger_core/standard_error.rb', line 39 def contents @contents ||= dsl_path && File.exist?(dsl_path) && File.read(dsl_path) end |
#message ⇒ String
The message of the exception reports the content of podspec for the line that generated the original exception.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/danger/danger_core/standard_error.rb', line 61 def @message ||= begin description, stacktrace = parse.values_at(:description, :stacktrace) msg = description msg = msg.red if msg.respond_to?(:red) msg << stacktrace if stacktrace msg end end |
#to_markdown ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/danger/danger_core/standard_error.rb', line 72 def to_markdown @markdown ||= begin description, stacktrace = parse.values_at(:description, :stacktrace) # Highlight failed method in markdown description = description.tr("'", "`") # Escape markdown brackets description = description.gsub(/<|>/) { |bracket| "\\#{bracket}" } md = "## Danger has errored" md << "#{description}\n" md << "```#{stacktrace}```" if stacktrace Markdown.new(md, nil, nil) end end |