From 15fbe050924515c7c6332091ba0c63a0467e916c Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 21 May 2008 17:34:52 -0700 Subject: [PATCH] tahoe_ls: improve error message when the target is missing --- src/allmydata/scripts/tahoe_ls.py | 11 ++++++++++- src/allmydata/test/test_system.py | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/allmydata/scripts/tahoe_ls.py b/src/allmydata/scripts/tahoe_ls.py index 13eda5ae..731cc527 100644 --- a/src/allmydata/scripts/tahoe_ls.py +++ b/src/allmydata/scripts/tahoe_ls.py @@ -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 diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 390e84d2..621c2c31 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -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): -- 2.45.2