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:
Rusty Russell
2023-01-03 14:53:15 +10:30
parent a1e894a445
commit 435f8d84dc
3 changed files with 58 additions and 4 deletions

View File

@@ -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.