#939 closed defect (fixed)
the CLI should fail gracefully when tahoe: doesn't exist and no alias is specified
| Reported by: | kevan | Owned by: | kevan |
|---|---|---|---|
| Priority: | major | Milestone: | 1.6.1 |
| Component: | code-frontend-cli | Version: | 1.6.0 |
| Keywords: | easy usability error alias reviewed | Cc: | |
| Launchpad Bug: |
Description
When I do 'tahoe ls' on a fresh node, I get
kevan@b8chem-87:~$ tahoe ls
Traceback (most recent call last):
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/support/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0', 'console_scripts', 'tahoe')()
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/cli.py", line 429, in list
rc = tahoe_ls.list(options)
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/tahoe_ls.py", line 18, in list
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
kevan@b8chem-87:~$
If I create an alias, then try again, I get
kevan@b8chem-87:~$ tahoe create-alias havasu
Alias 'havasu' created
kevan@b8chem-87:~$ tahoe ls
Traceback (most recent call last):
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/support/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0', 'console_scripts', 'tahoe')()
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/cli.py", line 429, in list
rc = tahoe_ls.list(options)
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/tahoe_ls.py", line 18, in list
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
File "/home/kevan/Desktop/software/tahoe/allmydata-tahoe-1.6.0/src/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
kevan@b8chem-87:~$
I should probably see something like
kevan@b8chem-87:~$ tahoe ls
Usage: tahoe <command> [command options] ls [options]
Options:
-q, --quiet Operate silently.
-V, --version Display version numbers and exit.
--version-and-path Display version numbers and paths to their locations
and exit.
-l, --long Use long format: show file sizes, and timestamps
--uri Show file/directory URIs
--readonly-uri Show readonly file/directory URIs
-F, --classify Append '/' to directory names, and '*' to mutable
--json Show the raw JSON output
-d, --node-directory= Look here to find out which Tahoe node should be used
for all operations. The directory should either
contain a full Tahoe node, or a file named node.url
which points to some other Tahoe node. It should also
contain a file named private/aliases which contains
the mapping from alias name to root dirnode URI.
[default: ~/.tahoe]
-u, --node-url= URL of the tahoe node to use, a URL like
"http://127.0.0.1:3456". This overrides the URL found
in the --node-directory .
--dir-cap= Which dirnode URI should be used as the 'tahoe' alias.
--help Display this help and exit.
List the contents of some portion of the grid.
error: no alias specified, and the default 'tahoe' alias doesn't exist.
kevan@b8chem-87:~$
or, perhaps better still, the CLI code could look in ~/.tahoe/private/aliases and choose one of those instead of requiring the 'tahoe' alias (failing gracefully with something like the message above if nothing is there, of course).
Attachments (3)
Change History (18)
comment:1 Changed at 2010-02-07T22:01:20Z by kevan
Changed at 2010-02-07T22:01:41Z by kevan
comment:2 Changed at 2010-02-07T22:42:41Z by kevan
- Summary changed from 'tahoe ls': fail gracefully when tahoe: doesn't exist and no alias is specified to the CLI should fail gracefully when tahoe: doesn't exist and no alias is specified
Other CLI commands process the alias in the same way as ls, though. Let's see how they do it.
(the 'tahoe-test' node has no aliases)
'tahoe backup'
pathos:~ kacarstensen$ tahoe backup -d tahoe-test entab.c software
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0-r4228', 'console_scripts', 'tahoe')()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/cli.py", line 473, in backup
rc = tahoe_backup.backup(options)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_backup.py", line 311, in backup
return bu.run()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_backup.py", line 95, in run
rootcap, path = get_alias(options.aliases, options.to_dir, DEFAULT_ALIAS)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
'tahoe check'
pathos:~ kacarstensen$ tahoe check -d tahoe-test
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0-r4228', 'console_scripts', 'tahoe')()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/cli.py", line 493, in check
rc = tahoe_check.check(options)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_check.py", line 18, in check
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
'tahoe cp'
pathos:~ kacarstensen$ tahoe cp -d tahoe-test entab.c dest Success: file copied
'tahoe get'
pathos:~ kacarstensen$ tahoe get -d tahoe-test file
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0-r4228', 'console_scripts', 'tahoe')()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/cli.py", line 434, in get
rc = tahoe_get.get(options)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_get.py", line 16, in get
rootcap, path = get_alias(aliases, from_file, DEFAULT_ALIAS)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
'tahoe manifest'
pathos:~ kacarstensen$ tahoe manifest -d tahoe-test
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0-r4228', 'console_scripts', 'tahoe')()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/cli.py", line 483, in manifest
rc = tahoe_manifest.manifest(options)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_manifest.py", line 87, in manifest
return ManifestStreamer().run(options)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_manifest.py", line 28, in run
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
'tahoe mkdir'
pathos:~ kacarstensen$ tahoe mkdir -d tahoe-test URI:DIR2:<dircap>
'tahoe mv'
pathos:~ kacarstensen$ tahoe mv -d tahoe-test afile anotherfile
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0-r4228', 'console_scripts', 'tahoe')()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/cli.py", line 463, in mv
rc = tahoe_mv.mv(options, mode="move")
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_mv.py", line 20, in mv
rootcap, from_path = get_alias(aliases, from_file, DEFAULT_ALIAS)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
'tahoe put'
pathos:~ kacarstensen$ tahoe put -d tahoe-test a.out 200 OK URI:CHK:<cap>
'tahoe rm'
pathos:~ kacarstensen$ tahoe rm -d tahoe-test afile
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/tahoe", line 8, in <module>
load_entry_point('allmydata-tahoe==1.6.0-r4228', 'console_scripts', 'tahoe')()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 102, in run
rc = runner(sys.argv[1:])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/runner.py", line 89, in runner
rc = cli.dispatch[command](so)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/cli.py", line 458, in rm
rc = tahoe_rm.rm(options)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/tahoe_rm.py", line 18, in rm
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/allmydata_tahoe-1.6.0_r4228-py2.6.egg/allmydata/scripts/common.py", line 150, in get_alias
return aliases[default], path
KeyError: 'tahoe'
'tahoe webopen'
pathos:~ kacarstensen$ tahoe webopen -d tahoe-test pathos:~ kacarstensen$
So I guess this isn't specific to 'tahoe ls', but instead is something that relates to many CLI tools. I'm updating the summary accordingly.
comment:3 Changed at 2010-02-07T23:24:10Z by kevan
- Owner set to kevan
- Status changed from new to assigned
comment:4 Changed at 2010-02-07T23:28:21Z by warner
I like the error: no alias specified, and the default 'tahoe' alias doesn't exist. message. I'd like it even better it we added a second line with instructions: To create one, use "tahoe create-alias tahoe".
And yeah, some CLI commands make as much (or more) sense without an alias.. "tahoe mkdir", "tahoe put", "tahoe get" are frequently used with raw caps, either accepting or returning them. It's the commands that always require aliases that are in most need of this improved error message.
comment:5 Changed at 2010-02-08T05:06:29Z by davidsarah
- Keywords easy usability error added
- Milestone changed from undecided to 1.7.0
#681 was a duplicate for tahoe ls. I've kept this ticket because it is more general and has more information.
comment:6 Changed at 2010-02-11T02:51:44Z by kevan
I'm attaching a patch that I think fixes this, and a few other problems related to explicitly specified aliases that don't exist.
When you invoke a command with no alias when tahoe: doesn't exist, or with an explicit alias that doesn't exist, you'll see something like:
wlan98-239:tahoe-1.6 kacarstensen$ ./bin/tahoe webopen fake: error: Unknown alias 'fake', please create it with 'tahoe add-alias' or 'tahoe create-alias'.
or
wlan1-92:tahoe-1.6 kacarstensen$ ./bin/tahoe get -d ~/tahoe-test fake error: No alias specified, and the default 'tahoe' alias doesn't exist. To create it, use 'tahoe create-alias tahoe'.
comment:7 Changed at 2010-02-11T02:53:09Z by kevan
- Keywords review-needed added
- Owner changed from kevan to nobody
- Status changed from assigned to new
comment:8 follow-up: ↓ 9 Changed at 2010-02-11T05:42:46Z by davidsarah
- Keywords review-needed removed
- Owner changed from nobody to kevan
I can't see any problems in the code.
In the tests patch:
- on line 30, "C:\Windows" should be "C:\\Windows".
- on line 71, the basedir should be cli/Ln/ln_with_nonexistent_alias, not cli/Ln/ln_without_alias.
- the string passed to failUnlessIn is sometimes "error", sometimes "error:", and sometimes "error: ". Make it consistent.
- the file open calls should use "wb" for the mode.
Also, tahoe webopen with no arguments currently raises TypeError: object of type 'NoneType' has no len() (#855). Either fix this, or add a TODO comment referencing #855 where the relevant test would be.
comment:9 in reply to: ↑ 8 Changed at 2010-02-11T05:55:34Z by davidsarah
Replying to davidsarah:
Also, tahoe webopen with no arguments currently raises TypeError: object of type 'NoneType' has no len()
Oh, that was because I hadn't specified --node-directory (which is a separate bug).
What is relevant to this ticket is that the tests should include test_webopen_without_alias.
comment:10 Changed at 2010-02-11T19:22:05Z by kevan
Thanks for the review.
So I'm clear: have you found a way to break tahoe webopen that is (or should be) fixed in this ticket, but isn't tested by my patches? Or is there some other reason that you'd like to see the test there?
comment:11 follow-up: ↓ 12 Changed at 2010-02-12T05:21:56Z by davidsarah
- Keywords alias added
Unless I'm mistaken, there should only be two backslashes in "C:
Windows", not four.
So I'm clear: have you found a way to break tahoe webopen that is (or should be) fixed in this ticket, but isn't tested by my patches?
No (I thought I had, but I was mistaken). There is currently no test for tahoe webopen without arguments, but I'll leave it up to you whether you want to fix that in this ticket.
comment:12 in reply to: ↑ 11 Changed at 2010-02-12T06:26:24Z by kevan
Replying to davidsarah:
Unless I'm mistaken, there should only be two backslashes in "C:
Windows", not four.
You're right -- I interpreted your comment as meaning that C:\ in a Windows path has two slashes, and I typed 4 to deal with escaping. But you meant that I literally should replace that string in the code with C:\\Windows. I'll fix that -- thanks.
No (I thought I had, but I was mistaken). There is currently no test for tahoe webopen without arguments, but I'll leave it up to you whether you want to fix that in this ticket.
I think it would be more appropriate to add it when #855 is fixed. It's helpful to have something that is broken when writing a test -- that way, you have something well-defined to test for.
comment:14 Changed at 2010-02-15T04:23:21Z by zooko
- Resolution set to fixed
- Status changed from new to closed
fixed by 63c8c6574745374a and c00a62a2e78a9b33. Thanks!
comment:15 Changed at 2010-02-15T04:25:14Z by zooko
- Milestone changed from 1.7.0 to 1.6.1

Here is a test that exercises the first case above and fails.
(whether or not we'd want to have a distinct test for having aliases none of which are called tahoe depends on how this is solved)