From 1f9332611f76ab170233e11b0d5bf58d24ca45e3 Mon Sep 17 00:00:00 2001 From: Michael Ripley Date: Thu, 25 Oct 2018 14:39:28 -0500 Subject: [PATCH] Nil error when mirror download fails This issue causes method in a Nil object to be read when a mirror download fails. In my case, this occurs due to my office's proxy blocking certain mirrors. This patch fixes the Nil access, exposing a more helpful error message. ## Before patch ``` $ brew install maven Error: An exception occurred within a child process: NoMethodError: undefined method `unlock' for nil:NilClass ``` ## After patch ``` $ brew install maven Error: An exception occurred within a child process: DownloadError: Failed to download resource "maven" Download failed: Couldn't determine mirror, try again later. ``` ## Steps to reproduce 1. Use brew 1.8.0 2. Ensure maven is not installed: ``` brew remove maven ``` 3. Ensure the download is not cached: ``` rm "$HOME/Library/Caches/Homebrew/downloads/*--apache-maven-*-bin.tar.gz" ``` 4. Make the mirrors unreachable by pointing them at a nonfunctional proxy: ``` export http{,s}_proxy=http://localhost:8080 export no_proxy=*.github.com,*.brew.sh ``` 5. Attempt package installation ``` brew install maven ``` --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index bddc679e36..399b0080d4 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -312,7 +312,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy retry end ensure - download_lock.unlock + download_lock&.unlock end def clear_cache