]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
tahoe_ls: improve error message when the target is missing
authorBrian Warner <warner@allmydata.com>
Thu, 22 May 2008 00:34:52 +0000 (17:34 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 22 May 2008 00:34:52 +0000 (17:34 -0700)
src/allmydata/scripts/tahoe_ls.py
src/allmydata/test/test_system.py

index 13eda5ae588cec3b998bf857d513deb5f8e36310..731cc52742b59e83cc07ed7635a36ef1e4db5605 100644 (file)
@@ -2,6 +2,7 @@
 import urllib, time
 import simplejson
 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
+from allmydata.scripts.common_http import do_http
 
 def list(nodeurl, aliases, where, config, stdout, stderr):
     if not nodeurl.endswith("/"):
@@ -15,7 +16,15 @@ def list(nodeurl, aliases, where, config, stdout, stderr):
         url += "/" + escape_path(path)
     assert not url.endswith("/")
     url += "?t=json"
-    data = urllib.urlopen(url).read()
+    resp = do_http("GET", url)
+    if resp.status == 404:
+        print >>stderr, "No such file or directory"
+        return 2
+    if resp.status != 200:
+        print >>stderr, "Error during GET: %s %s %s" % (resp.status,
+                                                        resp.reason,
+                                                        resp.read())
+    data = resp.read()
 
     if config['json']:
         print >>stdout, data
index 390e84d2862e4bfe6b50802e80f7e7c26e9a8724..621c2c313ea0760724dcd972883f3d83a04f6d53 100644 (file)
@@ -1594,6 +1594,13 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
         d.addCallback(run, "ls")
         d.addCallback(_check_empty_dir)
 
+        def _check_missing_dir((out,err)):
+            # TODO: check that rc==2
+            self.failUnlessEqual(out, "")
+            self.failUnlessEqual(err, "No such file or directory\n")
+        d.addCallback(run, "ls", "bogus")
+        d.addCallback(_check_missing_dir)
+
         files = []
         datas = []
         for i in range(10):