Skip to content

Commit d76a423

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#26067: util: improve bitcoin-wallet exit codes
fa2b8ae util: improve bitcoin-wallet exit codes (MacroFake) Pull request description: Refactors `bitcoin-wallet` so that it doesn't return a non-zero exit code by default, and makes the option handling more inline with the other binaries. i.e outputting `Error: too few parameters` if you don't pass any options. Fixing this means we can check the process output in `gen-manpages.py`; which addresses the remaining [review comment](bitcoin/bitcoin#24263 (comment)) from #24263. Top commit has no ACKs. Tree-SHA512: 80bd8098faefb4401ca1e4d49937ef6c960cf60ce0e7fb9dc38904fbc2fd92e319ec04570381da84943b7477845bf6be00e977f4c0451b247a6698662ce8f1bf
2 parents 0b02ce9 + fa2b8ae commit d76a423

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

contrib/devtools/gen-manpages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
for relpath in BINARIES:
3737
abspath = os.path.join(builddir, relpath)
3838
try:
39-
r = subprocess.run([abspath, '--version'], stdout=subprocess.PIPE, universal_newlines=True)
39+
r = subprocess.run([abspath, "--version"], stdout=subprocess.PIPE, check=True, universal_newlines=True)
4040
except IOError:
4141
print(f'{abspath} not found or not an executable', file=sys.stderr)
4242
sys.exit(1)

src/bitcoin-wallet.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
5050
argsman.AddCommand("createfromdump", "Create new wallet file from dumped records");
5151
}
5252

53-
static bool WalletAppInit(ArgsManager& args, int argc, char* argv[])
53+
static std::optional<int> WalletAppInit(ArgsManager& args, int argc, char* argv[])
5454
{
5555
SetupWalletToolArgs(args);
5656
std::string error_message;
5757
if (!args.ParseParameters(argc, argv, error_message)) {
5858
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
59-
return false;
59+
return EXIT_FAILURE;
6060
}
61-
if (argc < 2 || HelpRequested(args) || args.IsArgSet("-version")) {
61+
const bool missing_args{argc < 2};
62+
if (missing_args || HelpRequested(args) || args.IsArgSet("-version")) {
6263
std::string strUsage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
6364

6465
if (args.IsArgSet("-version")) {
@@ -73,20 +74,24 @@ static bool WalletAppInit(ArgsManager& args, int argc, char* argv[])
7374
strUsage += "\n" + args.GetHelpMessage();
7475
}
7576
tfm::format(std::cout, "%s", strUsage);
76-
return false;
77+
if (missing_args) {
78+
tfm::format(std::cerr, "Error: too few parameters\n");
79+
return EXIT_FAILURE;
80+
}
81+
return EXIT_SUCCESS;
7782
}
7883

7984
// check for printtoconsole, allow -debug
8085
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", args.GetBoolArg("-debug", false));
8186

8287
if (!CheckDataDirOption()) {
8388
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""));
84-
return false;
89+
return EXIT_FAILURE;
8590
}
8691
// Check for chain settings (Params() calls are only valid after this clause)
8792
SelectParams(args.GetChainName());
8893

89-
return true;
94+
return std::nullopt;
9095
}
9196

9297
MAIN_FUNCTION
@@ -106,7 +111,7 @@ MAIN_FUNCTION
106111
SetupEnvironment();
107112
RandomInit();
108113
try {
109-
if (!WalletAppInit(args, argc, argv)) return EXIT_FAILURE;
114+
if (const auto maybe_exit{WalletAppInit(args, argc, argv)}) return *maybe_exit;
110115
} catch (const std::exception& e) {
111116
PrintExceptionContinue(&e, "WalletAppInit()");
112117
return EXIT_FAILURE;

0 commit comments

Comments
 (0)