From d675ddc4988e559106f0d71ed548e6ffbed58c17 Mon Sep 17 00:00:00 2001 From: Louis Li Date: Sun, 29 Mar 2020 20:25:04 +0300 Subject: [PATCH 1/2] Check for empty organization and add useful error messages for clone/fork fail. --- lib/learn_open/lessons/base_lesson.rb | 3 +++ lib/learn_open/services/lesson_downloader.rb | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/learn_open/lessons/base_lesson.rb b/lib/learn_open/lessons/base_lesson.rb index 2b4d4f0..49b9f3e 100644 --- a/lib/learn_open/lessons/base_lesson.rb +++ b/lib/learn_open/lessons/base_lesson.rb @@ -22,6 +22,9 @@ def initialize(lesson_data, options = {}) @repo_path = lesson.clone_repo @organization, @name = repo_path.split('/') + if @organization.empty? + raise "The repo path had an empty organization. Most likely, you need to link your Github account to your Learn account through the Learn website." + end @git_server = lesson.git_server @dot_learn = lesson.dot_learn diff --git a/lib/learn_open/services/lesson_downloader.rb b/lib/learn_open/services/lesson_downloader.rb index e460b42..9cf8caf 100644 --- a/lib/learn_open/services/lesson_downloader.rb +++ b/lib/learn_open/services/lesson_downloader.rb @@ -43,9 +43,11 @@ def fork_repo(retries = 3) Timeout::timeout(15) do client.fork_repo(repo_name: lesson.name) end - rescue Timeout::Error + rescue Timeout::Error => e if retries > 0 io.puts "There was a problem forking this lesson. Retrying..." + io.puts "Git had the following error:" + io.puts e fork_repo(retries - 1) else io.puts "There is an issue connecting to Learn. Please try again." @@ -63,9 +65,11 @@ def clone_repo(retries = 3) Timeout::timeout(15) do git_adapter.clone("git@#{lesson.git_server}:#{lesson.repo_path}.git", lesson.name, path: location) end - rescue Git::GitExecuteError + rescue Git::GitExecuteError => e if retries > 0 io.puts "There was a problem cloning this lesson. Retrying..." if retries > 1 + io.puts "Git had the following error:" + io.puts e sleep(1) clone_repo(retries - 1) else @@ -75,7 +79,7 @@ def clone_repo(retries = 3) end rescue Timeout::Error if retries > 0 - io.puts "There was a problem cloning this lesson. Retrying..." + io.puts "There was a problem cloning this lesson (timed out). Retrying..." clone_repo(retries - 1) else io.puts "Cannot clone this lesson right now. Please try again." From 4081f3c124a45e23244f2d0663c8ee7d12bb321a Mon Sep 17 00:00:00 2001 From: Louis Li Date: Sun, 29 Mar 2020 20:33:27 +0300 Subject: [PATCH 2/2] Also check that name is not empty. --- lib/learn_open/lessons/base_lesson.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/learn_open/lessons/base_lesson.rb b/lib/learn_open/lessons/base_lesson.rb index 49b9f3e..5064d4a 100644 --- a/lib/learn_open/lessons/base_lesson.rb +++ b/lib/learn_open/lessons/base_lesson.rb @@ -22,7 +22,7 @@ def initialize(lesson_data, options = {}) @repo_path = lesson.clone_repo @organization, @name = repo_path.split('/') - if @organization.empty? + if @organization.empty? and not @name.empty? raise "The repo path had an empty organization. Most likely, you need to link your Github account to your Learn account through the Learn website." end