Browse Source

Merge pull request #1285 from sipa/initerror

Improve error reporting at startup
0.8
Pieter Wuille 13 years ago
parent
commit
9fc0a15cd4
  1. 71
      src/init.cpp

71
src/init.cpp

@ -119,15 +119,26 @@ bool AppInit(int argc, char* argv[])
return fRet; 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) { bool static Bind(const CService &addr) {
if (IsLimited(addr)) if (IsLimited(addr))
return false; return false;
std::string strError; std::string strError;
if (!BindListenPort(addr, strError)) if (!BindListenPort(addr, strError))
{ return InitError(strError);
ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
return false;
}
return true; return true;
} }
@ -352,10 +363,7 @@ bool AppInit2(int argc, char* argv[])
if (file) fclose(file); if (file) fclose(file);
static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
if (!lock.try_lock()) if (!lock.try_lock())
{ return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().string().c_str()));
ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().string().c_str()), _("Bitcoin"), wxOK|wxMODAL);
return false;
}
std::ostringstream strErrors; std::ostringstream strErrors;
// //
@ -414,8 +422,7 @@ bool AppInit2(int argc, char* argv[])
{ {
strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n"; strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
printf("%s", strErrors.str().c_str()); printf("%s", strErrors.str().c_str());
ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL); return InitError(strErrors.str());
return false;
} }
else else
strErrors << _("Error loading wallet.dat") << "\n"; strErrors << _("Error loading wallet.dat") << "\n";
@ -485,10 +492,7 @@ bool AppInit2(int argc, char* argv[])
printf("mapAddressBook.size() = %d\n", pwalletMain->mapAddressBook.size()); printf("mapAddressBook.size() = %d\n", pwalletMain->mapAddressBook.size());
if (!strErrors.str().empty()) if (!strErrors.str().empty())
{ return InitError(strErrors.str());
ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL);
return false;
}
// Add wallet transactions that aren't already in a block to mapTransactions // Add wallet transactions that aren't already in a block to mapTransactions
pwalletMain->ReacceptWalletTransactions(); pwalletMain->ReacceptWalletTransactions();
@ -541,20 +545,15 @@ bool AppInit2(int argc, char* argv[])
fUseProxy = true; fUseProxy = true;
addrProxy = CService(mapArgs["-proxy"], 9050); addrProxy = CService(mapArgs["-proxy"], 9050);
if (!addrProxy.IsValid()) if (!addrProxy.IsValid())
{ return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str()));
ThreadSafeMessageBox(_("Invalid -proxy address"), _("Bitcoin"), wxOK | wxMODAL);
return false;
}
} }
if (mapArgs.count("-noproxy")) if (mapArgs.count("-noproxy"))
{ {
BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) { BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) {
enum Network net = ParseNetwork(snet); enum Network net = ParseNetwork(snet);
if (net == NET_UNROUTABLE) { if (net == NET_UNROUTABLE)
ThreadSafeMessageBox(_("Unknown network specified in -noproxy"), _("Bitcoin"), wxOK | wxMODAL); return InitError(strprintf(_("Unknown network specified in -noproxy: '%s'"), snet.c_str()));
return false;
}
SetNoProxy(net); SetNoProxy(net);
} }
} }
@ -581,10 +580,8 @@ bool AppInit2(int argc, char* argv[])
if (mapArgs.count("-blocknet")) { if (mapArgs.count("-blocknet")) {
BOOST_FOREACH(std::string snet, mapMultiArgs["-blocknet"]) { BOOST_FOREACH(std::string snet, mapMultiArgs["-blocknet"]) {
enum Network net = ParseNetwork(snet); enum Network net = ParseNetwork(snet);
if (net == NET_UNROUTABLE) { if (net == NET_UNROUTABLE)
ThreadSafeMessageBox(_("Unknown network specified in -blocknet"), _("Bitcoin"), wxOK | wxMODAL); return InitError(strprintf(_("Unknown network specified in -blocknet: '%s'"), snet.c_str()));
return false;
}
SetLimited(net); SetLimited(net);
} }
} }
@ -595,6 +592,8 @@ bool AppInit2(int argc, char* argv[])
fNameLookup = true; fNameLookup = true;
fNoListen = !GetBoolArg("-listen", true); fNoListen = !GetBoolArg("-listen", true);
nSocksVersion = GetArg("-socks", 5); 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"]) BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
AddOneShot(strDest); AddOneShot(strDest);
@ -611,7 +610,10 @@ bool AppInit2(int argc, char* argv[])
std::string strError; std::string strError;
if (mapArgs.count("-bind")) { if (mapArgs.count("-bind")) {
BOOST_FOREACH(std::string strBind, mapMultiArgs["-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 { } else {
struct in_addr inaddr_any; struct in_addr inaddr_any;
@ -627,19 +629,20 @@ bool AppInit2(int argc, char* argv[])
if (mapArgs.count("-externalip")) 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); AddLocal(CService(strAddr, GetListenPort(), fNameLookup), LOCAL_MANUAL);
} }
}
if (mapArgs.count("-paytxfee")) if (mapArgs.count("-paytxfee"))
{ {
if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee)) if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
{ return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s'"), mapArgs["-paytxfee"].c_str()));
ThreadSafeMessageBox(_("Invalid amount for -paytxfee=<amount>"), _("Bitcoin"), wxOK | wxMODAL);
return false;
}
if (nTransactionFee > 0.25 * COIN) 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 @@ bool AppInit2(int argc, char* argv[])
RandAddSeedPerfmon(); RandAddSeedPerfmon();
if (!CreateThread(StartNode, NULL)) if (!CreateThread(StartNode, NULL))
ThreadSafeMessageBox(_("Error: CreateThread(StartNode) failed"), _("Bitcoin"), wxOK | wxMODAL); InitError(_("Error: could not start node"));
if (fServer) if (fServer)
CreateThread(ThreadRPCServer, NULL); CreateThread(ThreadRPCServer, NULL);

Loading…
Cancel
Save