6277: improve error message for missing file tokens.
authorradhika <radhika@curoverse.com>
Thu, 11 Jun 2015 20:11:28 +0000 (16:11 -0400)
committerradhika <radhika@curoverse.com>
Thu, 11 Jun 2015 20:11:28 +0000 (16:11 -0400)
sdk/ruby/lib/arvados/keep.rb
sdk/ruby/test/test_keep_manifest.rb

index 393266fb113160a4410f3e8aac1f479f51b68940..2006d3359da658a5a116ca9675b723a10d701369 100644 (file)
@@ -241,7 +241,7 @@ module Keep
         count = 0
         word = words.shift
         count += 1 if word =~ STREAM_REGEXP
-        raise ArgumentError.new "Manifest invalid for stream #{line_count}. Missing or invalid stream name #{word}" if count != 1
+        raise ArgumentError.new "Manifest invalid for stream #{line_count}: missing or invalid stream name #{word.inspect}" if count != 1
 
         count = 0
         word = words.shift
@@ -249,15 +249,18 @@ module Keep
           word = words.shift
           count += 1
         end
-        raise ArgumentError.new "Manifest invalid for stream #{line_count}. Missing or invalid locator #{word}" if count == 0
+        raise ArgumentError.new "Manifest invalid for stream #{line_count}: missing or invalid locator #{word.inspect}" if count == 0
 
         count = 0
         while word =~ FILE_REGEXP
           word = words.shift
           count += 1
         end
-        if(count == 0) or (word and word !~ FILE_REGEXP)
-          raise ArgumentError.new "Manifest invalid for stream #{line_count}. Missing or invalid file name #{word}"
+
+        if word
+          raise ArgumentError.new "Manifest invalid for stream #{line_count}: invalid file token #{word.inspect}"
+        elsif count == 0
+          raise ArgumentError.new "Manifest invalid for stream #{line_count}: no file tokens"
         end
       end
     end
index c49bd941d50c816f5cd101c84fc810e4fcfbaa6d..08965fa5fa0602862975ab35ebc562bbc318a693 100644 (file)
@@ -281,22 +281,23 @@ class ManifestTest < Minitest::Test
   end
 
   [
-   [false, 'abc d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt', 'invalid stream name abc'],
-   [false, 'd41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt', 'invalid stream name d41d8cd98f00b204e9800998ecf8427e'],
-   [false, '. d41d8cd98f00b204e9800998ecf8427 0:0:abc.txt', 'invalid locator d41d8cd98f00b204e9800998ecf8427'],
+   [false, 'abc d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt', "invalid stream name \"abc\""],
+   [false, 'd41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt', "invalid stream name \"d41d8cd98f00b204e9800998ecf8427e+0\""],
+   [false, '. d41d8cd98f00b204e9800998ecf8427 0:0:abc.txt', "invalid locator \"d41d8cd98f00b204e9800998ecf8427\""],
+   [false, '. d41d8cd98f00b204e9800998ecf8427e', "Manifest invalid for stream 1: no file tokens"],
    [true, '. d41d8cd98f00b204e9800998ecf8427e 0:0:abc.txt'],
    [true, '. d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt'],
    [true, '. d41d8cd98f00b204e9800998ecf8427e a41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt'], # 2 locators
    [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n/dir1 d41d8cd98f00b204e9800998ecf842 0:0:abc.txt",
-    'Manifest invalid for stream 2. Missing or invalid stream name /dir1'],
+    "Manifest invalid for stream 2: missing or invalid stream name \"/dir1\""],
    [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 d41d8cd98f00b204e9800998ecf842 0:0:abc.txt",
-    'Manifest invalid for stream 2. Missing or invalid locator d41d8cd98f00b204e9800998ecf842'],
+    "Manifest invalid for stream 2: missing or invalid locator \"d41d8cd98f00b204e9800998ecf842\""],
    [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 a41d8cd98f00b204e9800998ecf8427e+0 abc.txt",
-    'Manifest invalid for stream 2. Missing or invalid file name abc.txt'],
+    "Manifest invalid for stream 2: invalid file token \"abc.txt\""],
    [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 a41d8cd98f00b204e9800998ecf8427e+0 0:abc.txt",
-    'Manifest invalid for stream 2. Missing or invalid file name 0:abc.txt'],
+    "Manifest invalid for stream 2: invalid file token \"0:abc.txt\""],
    [false, ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt\n./dir1 a41d8cd98f00b204e9800998ecf8427e+0 0:0:abc.txt xyz.txt",
-    'Manifest invalid for stream 2. Missing or invalid file name xyz.txt'],
+    "Manifest invalid for stream 2: invalid file token \"xyz.txt\""],
   ].each do |ok, manifest, expected_error=nil|
     define_method "test_manifest_valid_#{ok}_#{manifest}_and_expect_error_#{expected_error}" do
       if ok