Error during xcversion install: `block in fetch': undefined method `match' for nil:NilClass (NoMethodError)
I got crash during run: xcversion install 11.2.1 --no-show-release-notes --no-ansi --no-progress on Jenkins.
/Users/{user}/.gem/ruby/2.4.0/gems/xcode-install-2.6.3/lib/xcode/install.rb:101:in 'block in fetch': undefined method `match' for nil:NilClass (NoMethodError)
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/lib/xcode/install.rb:81:in 'times'
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/lib/xcode/install.rb:81:in 'fetch'
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/lib/xcode/install.rb:144:in 'download'
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/lib/xcode/install.rb:376:in 'get_dmg'
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/lib/xcode/install.rb:280:in 'install_version'
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/lib/xcode/install/install.rb:50:in 'run'
from /Users/{user}/.gem/ruby/gems/claide-1.0.3/lib/claide/command.rb:334:in 'run'
from /Users/{user}/.gem/ruby/gems/xcode-install-2.6.3/bin/xcversion:12:in '<top (required)>'
from /Users/{user}/.gem/ruby/bin/xcversion:22:in 'load'
from /Users/{user}/.gem/ruby/bin/xcversion:22:in '<main>'
ruby version: 2.4.0 xcversion: 2.6.3 system_profiler SPSoftwareDataType: Software: System Software Overview: System Version: macOS 10.15.1 (19B88) Kernel Version: Darwin 19.0.0 Boot Volume: Macintosh HD Boot Mode: Normal Computer Name: {cname} User Name: {user} Secure Virtual Memory: Enabled System Integrity Protection: Enabled Time since boot: 1 day 20:46
Looks like the reason for the error is an empty progress_log_file. There is a check for its existence but if the file is empty (for any crazy reason) split will return an empty array and a result of last method will be nil.
Probably need a check for file emptiness or investigation why it is empty.
https://github.com/xcpretty/xcode-install/blob/18c402c3c487c83352a1669ba781fe9ac5574782/lib/xcode/install.rb#L90-L92
Insert the following lines instead of the line #92 progress_content = File.read(progress_log_file).split("\r").last
Looks like the reason for the error is an empty
progress_log_file. There is a check for its existence but if the file is empty (for any crazy reason)splitwill return an empty array and a result oflastmethod will benil. Probably need a check for file emptiness or investigation why it is empty.https://github.com/xcpretty/xcode-install/blob/18c402c3c487c83352a1669ba781fe9ac5574782/lib/xcode/install.rb#L90-L92
Insert the following lines instead od #92:
progress_content_lines = File.read(progress_log_file)
next unless !progress_content_lines.empty?
progress_content = progress_content_lines.split("\r").last