Adds better error reporting for problems with request body file
authorJoshua C. Randall <jcrandall@alum.mit.edu>
Mon, 22 Feb 2016 22:20:48 +0000 (22:20 +0000)
committerJoshua C. Randall <jcrandall@alum.mit.edu>
Mon, 22 Feb 2016 22:20:48 +0000 (22:20 +0000)
Reports clear error messages if the specified file does not
exist or is not readable.

sdk/cli/bin/arv

index 6811a4473fe0cc82571f60bb5b0cd52ce61c562a..b91d137a486f7b5cb727900068ec616ed7af7922 100755 (executable)
@@ -643,7 +643,17 @@ if resource_body
     if resource_body == '-'
       _resource_body_file = $stdin
     else
-      _resource_body_file = File.open(resource_body, 'r')
+      if File.readable? resource_body
+        _resource_body_file = File.open(resource_body, 'r')
+      else
+        if File.exists? resource_body
+          # specified file exists but is not readable
+          abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' exists but is not readable."
+        else
+          # specified file does not exist
+          abort "File '#{resource_body}' specified for option '--#{resource_schema.to_sym}' does not exist."
+        end
+      end
     end
     resource_body = _resource_body_file.read()
     _resource_body_file.close()