Exception: Pod::DSLError
- Inherits:
-
Informative
- Object
- StandardError
- StandardError
- PlainInformative
- Informative
- Pod::DSLError
- Defined in:
- lib/cocoapods-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
-
#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.
-
#underlying_exception ⇒ Exception
readonly
The exception raised by the evaluation of the dsl file.
Instance Method Summary collapse
-
#contents ⇒ String
The contents of the DSL that cause the exception to be raised.
-
#initialize(description, dsl_path, underlying_exception, 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.
Constructor Details
#initialize(description, dsl_path, underlying_exception, contents = nil) ⇒ DSLError
Returns a new instance of DSLError.
28 29 30 31 32 33 |
# File 'lib/cocoapods-core/standard_error.rb', line 28 def initialize(description, dsl_path, , contents = nil) @description = description @dsl_path = dsl_path @underlying_exception = @contents = contents end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns the description that should be presented to the user.
14 15 16 |
# File 'lib/cocoapods-core/standard_error.rb', line 14 def description @description end |
#dsl_path ⇒ String (readonly)
Returns the path of the dsl file that raised the exception.
18 19 20 |
# File 'lib/cocoapods-core/standard_error.rb', line 18 def dsl_path @dsl_path end |
#underlying_exception ⇒ Exception (readonly)
Returns the exception raised by the evaluation of the dsl file.
23 24 25 |
# File 'lib/cocoapods-core/standard_error.rb', line 23 def @underlying_exception end |
Instance Method Details
#contents ⇒ String
Returns the contents of the DSL that cause the exception to be raised.
38 39 40 41 42 |
# File 'lib/cocoapods-core/standard_error.rb', line 38 def contents @contents ||= begin dsl_path && File.exist?(dsl_path) && File.read(dsl_path) end end |
#message ⇒ String
The message of the exception reports the content of podspec for the line that generated the original exception.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cocoapods-core/standard_error.rb', line 62 def @message ||= begin trace_line, description = parse_line_number_from_description m = "\n[!] #{description}.\n" m = m.red if m.respond_to?(:red) backtrace = .backtrace return m unless backtrace && dsl_path && contents trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) } || trace_line return m unless trace_line line_numer = trace_line.split(':')[1].to_i - 1 return m unless line_numer lines = contents.lines indent = ' # ' indicator = indent.tr('#', '>') first_line = (line_numer.zero?) last_line = (line_numer == (lines.count - 1)) m << "\n" m << "#{indent}from #{trace_line.gsub(/:in.*$/, '')}\n" m << "#{indent}-------------------------------------------\n" m << "#{indent}#{lines[line_numer - 1]}" unless first_line m << "#{indicator}#{lines[line_numer]}" m << "#{indent}#{lines[line_numer + 1]}" unless last_line m << "\n" unless m.end_with?("\n") m << "#{indent}-------------------------------------------\n" end end |