[ARVADOS] updated: 632617ca32cb0be73a0a7cfee5a19b2255c7154c

git at public.curoverse.com git at public.curoverse.com
Thu Jun 26 09:29:02 EDT 2014


Summary of changes:
 sdk/cli/bin/arv | 71 ++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 24 deletions(-)

       via  632617ca32cb0be73a0a7cfee5a19b2255c7154c (commit)
      from  64437af24f74ec3f48b1a5694a5805d52dfc4967 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 632617ca32cb0be73a0a7cfee5a19b2255c7154c
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Jun 26 09:28:57 2014 -0400

    Improve arv edit failure handling.

diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 6842703..259b38a 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -184,6 +184,8 @@ def arv_edit client, arvados, global_opts, remaining_opts
     abort "Could not determine resource type #{m[2]}"
   end
 
+  require 'fileutils'
+
   api_method = 'arvados.' + rsc + '.get'
 
   result = client.execute(:api_method => eval(api_method),
@@ -251,8 +253,13 @@ def arv_edit client, arvados, global_opts, remaining_opts
           n += 1
         end
         puts "\nTry again (y/n)? "
-        yn = $stdin.read 1
+        yn = "X"
+        while not ["y", "Y", "n", "N"].include?(yn)
+          yn = $stdin.read 1
+        end
         if yn == 'n' or yn == 'N'
+          FileUtils::cp tmp.path, tmp.path + ".saved"
+          puts "Saved contents to " + tmp.path + ".saved"
           exit 1
         end
       end
@@ -262,31 +269,47 @@ def arv_edit client, arvados, global_opts, remaining_opts
     end
   end
 
-  tmp.close(true)
-
-  if newobj != results
-    api_method = 'arvados.' + rsc + '.update'
-    dumped = Oj.dump(newobj)
-    result = client.execute(:api_method => eval(api_method),
-                            :parameters => {"uuid" => n, rsc.singularize => dumped},
-                            :authenticated => false,
-                            :headers => {
-                              authorization: 'OAuth2 '+ENV['ARVADOS_API_TOKEN']
-                            })
-
-    begin
-      results = JSON.parse result.body
-    rescue JSON::ParserError => e
-      abort "Failed to parse server response:\n" + e.to_s
-    end
+  begin
+    if newobj != results
+      api_method = 'arvados.' + rsc + '.update'
+      dumped = Oj.dump(newobj)
+
+      begin
+        result = client.execute(:api_method => eval(api_method),
+                                :parameters => {"uuid" => n},
+                                :body => { rsc.singularize => dumped },
+                                :authenticated => false,
+                                :headers => {
+                                  authorization: 'OAuth2 '+ENV['ARVADOS_API_TOKEN']
+                                })
+      rescue Exception => e
+        FileUtils::cp tmp.path, tmp.path + ".saved"
+        puts "Error communicating with server, error was #{e}"
+        puts "Update body was:"
+        puts dumped
+        puts "Saved contents to " + tmp.path + ".saved"
+        abort
+      end
+
+      begin
+        results = JSON.parse result.body
+      rescue JSON::ParserError => e
+        abort "Failed to parse server response:\n" + e.to_s
+      end
 
-    if result.response.status != 200
-      puts "Update failed.  Server responded #{result.response.status}: #{results['errors']} "
-      puts "Update body was:"
-      puts dumped
+      if result.response.status != 200
+        FileUtils::cp tmp.path, tmp.path + ".saved"
+        puts "Update failed.  Server responded #{result.response.status}: #{results['errors']} "
+        puts "Update body was:"
+        puts dumped
+        puts "Saved contents to " + tmp.path + ".saved"
+        abort
+      end
+    else
+      puts "Object is unchanged, did not update."
     end
-  else
-    puts "Object is unchanged, did not update."
+  ensure
+    tmp.close(true)
   end
 
   exit 0

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list