mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 06:54:30 +01:00
lightning-cli: fix error code on invalid options, document them.
The top of the file indicates the following errors:
#define NO_ERROR 0
#define ERROR_FROM_LIGHTNINGD 1
#define ERROR_TALKING_TO_LIGHTNINGD 2
#define ERROR_USAGE 3
But we didn't use the right one for opt_parse failure, and didn't use the
correct constants everywhere.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -937,6 +937,39 @@ def test_cli(node_factory):
|
||||
j, _ = json.JSONDecoder().raw_decode(out)
|
||||
assert j == {'help': [{'command': 'help [command]'}]}
|
||||
|
||||
# lightningd errors should exit with status 1.
|
||||
ret = subprocess.run(['cli/lightning-cli',
|
||||
'--network={}'.format(TEST_NETWORK),
|
||||
'--lightning-dir={}'
|
||||
.format(l1.daemon.lightning_dir),
|
||||
'unknown-command'])
|
||||
assert ret.returncode == 1
|
||||
|
||||
# Can't contact will exit with status code 2.
|
||||
ret = subprocess.run(['cli/lightning-cli',
|
||||
'--network={}'.format(TEST_NETWORK),
|
||||
'--lightning-dir=xxx',
|
||||
'help'])
|
||||
assert ret.returncode == 2
|
||||
|
||||
# Malformed parameter (invalid json) will exit with status code 3.
|
||||
ret = subprocess.run(['cli/lightning-cli',
|
||||
'--network={}'.format(TEST_NETWORK),
|
||||
'--lightning-dir={}'
|
||||
.format(l1.daemon.lightning_dir),
|
||||
'listpeers',
|
||||
'[xxx]'])
|
||||
assert ret.returncode == 3
|
||||
|
||||
# Bad usage should exit with status 3.
|
||||
ret = subprocess.run(['cli/lightning-cli',
|
||||
'--bad-param',
|
||||
'--network={}'.format(TEST_NETWORK),
|
||||
'--lightning-dir={}'
|
||||
.format(l1.daemon.lightning_dir),
|
||||
'help'])
|
||||
assert ret.returncode == 3
|
||||
|
||||
# Test missing parameters.
|
||||
try:
|
||||
# This will error due to missing parameters.
|
||||
|
||||
Reference in New Issue
Block a user