Exception: Pod::DSLError

Inherits:
Informative show all
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

Instance Method Summary collapse

Constructor Details

#initialize(description, dsl_path, backtrace) ⇒ DSLError

Returns a new instance of DSLError.

Parameters:

  • backtrace (Exception)

    @see backtrace

  • dsl_path (String)

    @see dsl_path



28
29
30
31
32
# File 'lib/cocoapods-core/standard_error.rb', line 28

def initialize(description, dsl_path, backtrace)
  @description = description
  @dsl_path    = dsl_path
  @backtrace   = backtrace
end

Instance Attribute Details

#backtraceException (readonly)

Returns the backtrace of the exception raised by the evaluation of the dsl file.

Returns:

  • (Exception)

    the backtrace of the exception raised by the evaluation of the dsl file.



23
24
25
# File 'lib/cocoapods-core/standard_error.rb', line 23

def backtrace
  @backtrace
end

#descriptionString (readonly)

Returns the description that should be presented to the user.

Returns:

  • (String)

    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_pathString (readonly)

Returns the path of the dsl file that raised the exception.

Returns:

  • (String)

    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

Instance Method Details

#messageString

The message of the exception reports the content of podspec for the line that generated the original exception.

Examples:

Output


Invalid podspec at `RestKit.podspec` - undefined method
`exclude_header_search_paths=' for #<Pod::Specification for
`RestKit/Network (0.9.3)`>

    from spec-repos/master/RestKit/0.9.3/RestKit.podspec:36
    -------------------------------------------
        # because it would break: #import <CoreData/CoreData.h>
 >      ns.exclude_header_search_paths = 'Code/RestKit.h'
      end
    -------------------------------------------

Returns:

  • (String)

    the message of the exception.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cocoapods-core/standard_error.rb', line 52

def message
  unless @message
    m = "\n[!] "
    m << description
    m << ". Updating CocoaPods might fix the issue.\n"
    m = m.red if m.respond_to?(:red)

    return m unless backtrace && dsl_path && File.exist?(dsl_path)

    trace_line = backtrace.find { |l| l.include?(dsl_path.to_s) }
    return m unless trace_line
    line_numer = trace_line.split(':')[1].to_i - 1
    return m unless line_numer
    lines      = File.readlines(dsl_path.to_s)
    indent     = ' #  '
    indicator  = indent.dup.gsub('#', '>')
    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"
    m << ''
    @message = m
  end
  @message
end