tahoe_ls: improve error message when the target is missing

This commit is contained in:
Brian Warner 2008-05-21 17:34:52 -07:00
parent 282e22abcf
commit 15fbe05092
2 changed files with 17 additions and 1 deletions

View 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

View 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):