Module: Pod::UserInterface::ErrorReport

Defined in:
lib/cocoapods/user_interface/error_report.rb

Class Method Summary collapse

Class Method Details

.`(other) ⇒ Object (private)


127
128
129
130
131
# File 'lib/cocoapods/user_interface/error_report.rb', line 127

def `(other)
  super
rescue Errno::ENOENT => e
  "Unable to find an executable (#{e})"
end

.error_from_podfile(error) ⇒ Object (private)


137
138
139
140
141
# File 'lib/cocoapods/user_interface/error_report.rb', line 137

def error_from_podfile(error)
  if error.message =~ /Podfile:(\d*)/
    "\nIt appears to have originated from your Podfile at line #{Regexp.last_match[1]}.\n"
  end
end

.git_hash(source) ⇒ String (private)

Returns the current git SHA.

Parameters:

  • source (Source)

    a git source

Returns:

  • (String)

    the current git SHA


196
197
198
199
200
# File 'lib/cocoapods/user_interface/error_report.rb', line 196

def git_hash(source)
  Dir.chdir(source.repo) do
    `git rev-parse HEAD 2>&1`
  end
end

.git_informationObject (private)


163
164
165
# File 'lib/cocoapods/user_interface/error_report.rb', line 163

def git_information
  `git --version`.strip.split("\n").first
end

.host_informationObject (private)


153
154
155
156
# File 'lib/cocoapods/user_interface/error_report.rb', line 153

def host_information
  product, version, build = `sw_vers`.strip.split("\n").map { |line| line.split(':').last.strip }
  "#{product} #{version} (#{build})"
end

.installed_pluginsObject (private)


167
168
169
170
# File 'lib/cocoapods/user_interface/error_report.rb', line 167

def installed_plugins
  CLAide::Command::PluginManager.specifications.
    reduce({}) { |hash, s| hash.tap { |h| h[s.name] = s.version.to_s } }
end

.issues_url(exception) ⇒ Object (private)


147
148
149
150
151
# File 'lib/cocoapods/user_interface/error_report.rb', line 147

def issues_url(exception)
  message = remove_color(pathless_exception_message(exception.message))
  'https://github.com/CocoaPods/CocoaPods/search?q=' \
  "#{CGI.escape(message)}&type=Issues"
end

.markdown_podfileObject


104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cocoapods/user_interface/error_report.rb', line 104

def markdown_podfile
  return '' unless Config.instance.podfile_path && Config.instance.podfile_path.exist?
  <<-EOS

### Podfile

```ruby
#{Config.instance.podfile_path.read.strip}
```
EOS
end

.original_commandObject (private)


186
187
188
# File 'lib/cocoapods/user_interface/error_report.rb', line 186

def original_command
  "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
end

.pathless_exception_message(message) ⇒ Object (private)


133
134
135
# File 'lib/cocoapods/user_interface/error_report.rb', line 133

def pathless_exception_message(message)
  message.gsub(/- \(.*\):/, '-')
end

.plugins_stringObject


96
97
98
99
100
101
102
# File 'lib/cocoapods/user_interface/error_report.rb', line 96

def plugins_string
  plugins = installed_plugins
  max_name_length = plugins.keys.map(&:length).max
  plugins.map do |name, version|
    "#{name.ljust(max_name_length)} : #{version}"
  end.sort.join("\n")
end

.remove_color(string) ⇒ Object (private)


143
144
145
# File 'lib/cocoapods/user_interface/error_report.rb', line 143

def remove_color(string)
  string.gsub(/\e\[(\d+)m/, '')
end

.repo_informationObject (private)


172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/cocoapods/user_interface/error_report.rb', line 172

def repo_information
  Config.instance.sources_manager.all.map do |source|
    repo = source.repo
    if source.is_a?(Pod::CDNSource)
      "#{repo.basename} - CDN - #{source.url}"
    elsif source.git?
      sha = git_hash(source)
      "#{repo.basename} - git - #{source.url} @ #{sha}"
    else
      "#{repo.basename} - #{source.type}"
    end
  end
end

.report(exception) ⇒ Object


11
12
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
# File 'lib/cocoapods/user_interface/error_report.rb', line 11

def report(exception)
  <<-EOS

#{'――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}

### Command

```
#{original_command}
```

#{report_instructions}

#{stack}
### Plugins

```
#{plugins_string}
```
#{markdown_podfile}
### Error

```
#{exception.class} - #{exception.message.force_encoding('UTF-8')}
#{exception.backtrace.join("\n") if exception.backtrace}
```

#{'――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}

#{'[!] Oh no, an error occurred.'.red}
#{error_from_podfile(exception)}
#{'Search for existing GitHub issues similar to yours:'.yellow}
#{issues_url(exception)}

#{'If none exists, create a ticket, with the template displayed above, on:'.yellow}
https://github.com/CocoaPods/CocoaPods/issues/new

#{'Be sure to first read the contributing guide for details on how to properly submit a ticket:'.yellow}
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

EOS
end

.report_instructionsObject


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cocoapods/user_interface/error_report.rb', line 56

def report_instructions
  <<-EOS
### Report

* What did you do?

* What did you expect to happen?

* What happened instead?
EOS
end

.search_for_exceptions(exception) ⇒ Object


116
117
118
119
120
121
122
123
# File 'lib/cocoapods/user_interface/error_report.rb', line 116

def search_for_exceptions(exception)
  inspector = GhInspector::Inspector.new 'cocoapods', 'cocoapods'
  message_delegate = UserInterface::InspectorReporter.new
  inspector.search_exception exception, message_delegate
rescue => e
  warn "Searching for inspections failed: #{e}"
  nil
end

.stackObject


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
93
94
# File 'lib/cocoapods/user_interface/error_report.rb', line 68

def stack
  parts = {
    'CocoaPods' => Pod::VERSION,
    'Ruby' => RUBY_DESCRIPTION,
    'RubyGems' => Gem::VERSION,
    'Host' => host_information,
    'Xcode' => xcode_information,
    'Git' => git_information,
    'Ruby lib dir' => RbConfig::CONFIG['libdir'],
    'Repositories' => repo_information,
  }
  justification = parts.keys.map(&:size).max

  str = <<-EOS
### Stack

```
EOS
  parts.each do |name, value|
    str << name.rjust(justification)
    str << ' : '
    str << Array(value).join("\n" << (' ' * (justification + 3)))
    str << "\n"
  end

  str << "```\n"
end

.xcode_informationObject (private)


158
159
160
161
# File 'lib/cocoapods/user_interface/error_report.rb', line 158

def xcode_information
  version, build = `xcodebuild -version`.strip.split("\n").map { |line| line.split(' ').last }
  "#{version} (#{build})"
end