github-education-resources / teachers_pet

Command line tool to help teachers use GitHub in their classrooms
https://education.github.com/guide
MIT License
187 stars 74 forks source link

create_student_teams fails and quits for nonexisting users #128

Open Soly opened 8 years ago

Soly commented 8 years ago

teachers_pet doesn't fail gracefully for nonexisting users. This issue probably exists for some other commands too.

My current workaround for create_student_teams is this, which just catches the error and continues.

--- a/lib/teachers_pet/client_decorator.rb
+++ b/lib/teachers_pet/client_decorator.rb
@@ -52,8 +52,12 @@ module TeachersPet
             puts " -> @#{username} is already on @#{organization}/#{team[:name]}"
           else
             # https://github.com/octokit/octokit.rb/pull/518
-            self.add_team_membership(team[:id], username, accept: 'application/vnd.github.the-wasp-preview+json')
-            puts " -> @#{username} has been added to @#{organization}/#{team[:name]}"
+            begin
+              self.add_team_membership(team[:id], username, accept: 'application/vnd.github.the-wasp-preview+json')
+              puts " -> @#{username} has been added to @#{organization}/#{team[:name]}"
+            rescue
+              puts " -> Error adding user to team. #{username} might not exist."
+            end
           end
         end
       end