From 4ae5e72128f605d0fc25bba1d42c0434375d712e Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 7 Apr 2014 10:10:01 +0200 Subject: [PATCH] Show error message if ReadConfigFile fails A runaway exception was raised if ReadConfigFile fails (usually due to a parse error in bitcoin.conf). Show an error message instead. Fixes #4013. --- src/bitcoin-cli.cpp | 7 ++++++- src/bitcoind.cpp | 8 +++++++- src/qt/bitcoin.cpp | 8 +++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 817369fe95e..ca6950a162e 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -27,7 +27,12 @@ static bool AppInitRPC(int argc, char* argv[]) fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str()); return false; } - ReadConfigFile(mapArgs, mapMultiArgs); + try { + ReadConfigFile(mapArgs, mapMultiArgs); + } catch(std::exception &e) { + fprintf(stderr,"Error reading configuration file: %s\n", e.what()); + return false; + } // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause) if (!SelectParamsFromCommandLine()) { fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n"); diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 4882a005328..17aa0c9d4ba 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -70,7 +70,13 @@ bool AppInit(int argc, char* argv[]) fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str()); return false; } - ReadConfigFile(mapArgs, mapMultiArgs); + try + { + ReadConfigFile(mapArgs, mapMultiArgs); + } catch(std::exception &e) { + fprintf(stderr,"Error reading configuration file: %s\n", e.what()); + return false; + } // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause) if (!SelectParamsFromCommandLine()) { fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n"); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 0db4308bf68..696e65ec191 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -507,7 +507,13 @@ int main(int argc, char *argv[]) QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"]))); return 1; } - ReadConfigFile(mapArgs, mapMultiArgs); + try { + ReadConfigFile(mapArgs, mapMultiArgs); + } catch(std::exception &e) { + QMessageBox::critical(0, QObject::tr("Bitcoin"), + QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what())); + return false; + } /// 7. Determine network (and switch to network specific options) // - Do not call Params() before this step