Mercurial > hg > bitcoin
changeset 2540:b3bc9f4684cc draft
Merge pull request #1285 from sipa/initerror
Improve error reporting at startup
author | Pieter Wuille <pieter.wuille@gmail.com> |
---|---|
date | Sun, 13 May 2012 06:01:21 -0700 (2012-05-13) |
parents | 6bb9b0ad1725 (current diff) 50e4c9b6b43a (diff) |
children | d082f875463b aed702ac5924 |
files | src/init.cpp |
diffstat | 1 files changed, 37 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/src/init.cpp +++ b/src/init.cpp @@ -119,15 +119,26 @@ return fRet; } +bool static InitError(const std::string &str) +{ + ThreadSafeMessageBox(str, _("Bitcoin"), wxOK | wxMODAL); + return false; + +} + +bool static InitWarning(const std::string &str) +{ + ThreadSafeMessageBox(str, _("Bitcoin"), wxOK | wxICON_EXCLAMATION | wxMODAL); + return true; +} + + bool static Bind(const CService &addr) { if (IsLimited(addr)) return false; std::string strError; if (!BindListenPort(addr, strError)) - { - ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL); - return false; - } + return InitError(strError); return true; } @@ -352,10 +363,7 @@ if (file) fclose(file); static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); if (!lock.try_lock()) - { - ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().string().c_str()), _("Bitcoin"), wxOK|wxMODAL); - return false; - } + return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().string().c_str())); std::ostringstream strErrors; // @@ -414,8 +422,7 @@ { strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n"; printf("%s", strErrors.str().c_str()); - ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL); - return false; + return InitError(strErrors.str()); } else strErrors << _("Error loading wallet.dat") << "\n"; @@ -485,10 +492,7 @@ printf("mapAddressBook.size() = %d\n", pwalletMain->mapAddressBook.size()); if (!strErrors.str().empty()) - { - ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL); - return false; - } + return InitError(strErrors.str()); // Add wallet transactions that aren't already in a block to mapTransactions pwalletMain->ReacceptWalletTransactions(); @@ -541,20 +545,15 @@ fUseProxy = true; addrProxy = CService(mapArgs["-proxy"], 9050); if (!addrProxy.IsValid()) - { - ThreadSafeMessageBox(_("Invalid -proxy address"), _("Bitcoin"), wxOK | wxMODAL); - return false; - } + return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str())); } if (mapArgs.count("-noproxy")) { BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) { enum Network net = ParseNetwork(snet); - if (net == NET_UNROUTABLE) { - ThreadSafeMessageBox(_("Unknown network specified in -noproxy"), _("Bitcoin"), wxOK | wxMODAL); - return false; - } + if (net == NET_UNROUTABLE) + return InitError(strprintf(_("Unknown network specified in -noproxy: '%s'"), snet.c_str())); SetNoProxy(net); } } @@ -581,10 +580,8 @@ if (mapArgs.count("-blocknet")) { BOOST_FOREACH(std::string snet, mapMultiArgs["-blocknet"]) { enum Network net = ParseNetwork(snet); - if (net == NET_UNROUTABLE) { - ThreadSafeMessageBox(_("Unknown network specified in -blocknet"), _("Bitcoin"), wxOK | wxMODAL); - return false; - } + if (net == NET_UNROUTABLE) + return InitError(strprintf(_("Unknown network specified in -blocknet: '%s'"), snet.c_str())); SetLimited(net); } } @@ -595,6 +592,8 @@ fNameLookup = true; fNoListen = !GetBoolArg("-listen", true); nSocksVersion = GetArg("-socks", 5); + if (nSocksVersion != 4 && nSocksVersion != 5) + return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion)); BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"]) AddOneShot(strDest); @@ -611,7 +610,10 @@ std::string strError; if (mapArgs.count("-bind")) { BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) { - fBound |= Bind(CService(strBind, GetListenPort(), false)); + CService addrBind(strBind, GetListenPort(), false); + if (!addrBind.IsValid()) + return InitError(strprintf(_("Cannot resolve -bind address: '%s'"), strBind.c_str())); + fBound |= Bind(addrBind); } } else { struct in_addr inaddr_any; @@ -627,19 +629,20 @@ if (mapArgs.count("-externalip")) { - BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"]) + BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"]) { + CService addrLocal(strAddr, GetListenPort(), fNameLookup); + if (!addrLocal.IsValid()) + return InitError(strprintf(_("Cannot resolve -externalip address: '%s'"), strAddr.c_str())); AddLocal(CService(strAddr, GetListenPort(), fNameLookup), LOCAL_MANUAL); + } } if (mapArgs.count("-paytxfee")) { if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee)) - { - ThreadSafeMessageBox(_("Invalid amount for -paytxfee=<amount>"), _("Bitcoin"), wxOK | wxMODAL); - return false; - } + return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s'"), mapArgs["-paytxfee"].c_str())); if (nTransactionFee > 0.25 * COIN) - ThreadSafeMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), _("Bitcoin"), wxOK | wxICON_EXCLAMATION | wxMODAL); + InitWarning(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction.")); } // @@ -651,7 +654,7 @@ RandAddSeedPerfmon(); if (!CreateThread(StartNode, NULL)) - ThreadSafeMessageBox(_("Error: CreateThread(StartNode) failed"), _("Bitcoin"), wxOK | wxMODAL); + InitError(_("Error: could not start node")); if (fServer) CreateThread(ThreadRPCServer, NULL);