Skip to content

Commit

Permalink
Make InitError bilingual
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 5, 2020
1 parent 917ca93 commit 7e923d4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 73 deletions.
14 changes: 7 additions & 7 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool AppInit(int argc, char* argv[])
SetupServerArgs(node);
std::string error;
if (!gArgs.ParseParameters(argc, argv, error)) {
return InitError(strprintf("Error parsing command line arguments: %s\n", error));
return InitError(Untranslated(strprintf("Error parsing command line arguments: %s\n", error)));
}

// Process help and version before taking care about datadir
Expand All @@ -80,22 +80,22 @@ static bool AppInit(int argc, char* argv[])
try
{
if (!CheckDataDirOption()) {
return InitError(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "")));
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""))));
}
if (!gArgs.ReadConfigFiles(error, true)) {
return InitError(strprintf("Error reading configuration file: %s\n", error));
return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
}
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(gArgs.GetChainName());
} catch (const std::exception& e) {
return InitError(strprintf("%s\n", e.what()));
return InitError(Untranslated(strprintf("%s\n", e.what())));
}

// Error out when loose non-argument tokens are encountered on command line
for (int i = 1; i < argc; i++) {
if (!IsSwitchChar(argv[i][0])) {
return InitError(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]));
return InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i])));
}
}

Expand Down Expand Up @@ -130,13 +130,13 @@ static bool AppInit(int argc, char* argv[])

// Daemonize
if (daemon(1, 0)) { // don't chdir (1), do close FDs (0)
return InitError(strprintf("daemon() failed: %s\n", strerror(errno)));
return InitError(Untranslated(strprintf("daemon() failed: %s\n", strerror(errno))));
}
#if defined(MAC_OSX)
#pragma GCC diagnostic pop
#endif
#else
return InitError("-daemon is not supported on this operating system\n");
return InitError(Untranslated("-daemon is not supported on this operating system\n"));
#endif // HAVE_DECL_DAEMON
}
// Lock data directory after daemonization
Expand Down
97 changes: 48 additions & 49 deletions src/init.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class ChainImpl : public Chain
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
void initWarning(const std::string& message) override { InitWarning(message); }
void initError(const std::string& message) override { InitError(message); }
void initError(const bilingual_str& message) override { InitError(message); }
void showProgress(const std::string& title, int progress, bool resume_possible) override
{
::uiInterface.ShowProgress(title, progress, resume_possible);
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CScheduler;
class Coin;
class uint256;
enum class RBFTransactionState;
struct bilingual_str;
struct CBlockLocator;
struct FeeCalculation;
struct NodeContext;
Expand Down Expand Up @@ -227,7 +228,7 @@ class Chain
virtual void initWarning(const std::string& message) = 0;

//! Send init error.
virtual void initError(const std::string& message) = 0;
virtual void initError(const bilingual_str& message) = 0;

//! Send progress indicator.
virtual void showProgress(const std::string& title, int progress, bool resume_possible) = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <txmempool.h>
#include <ui_interface.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <warnings.h>

Expand All @@ -54,7 +55,7 @@ namespace {
class NodeImpl : public Node
{
public:
void initError(const std::string& message) override { InitError(message); }
void initError(const std::string& message) override { InitError(Untranslated(message)); }
bool parseParameters(int argc, const char* const argv[], std::string& error) override
{
return gArgs.ParseParameters(argc, argv, error);
Expand Down
5 changes: 2 additions & 3 deletions src/ui_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g
void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); }
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }


bool InitError(const std::string& str)
bool InitError(const bilingual_str& str)
{
uiInterface.ThreadSafeMessageBox(Untranslated(str), "", CClientUIInterface::MSG_ERROR);
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ class CClientUIInterface
};

/** Show warning message **/
// TODO: InitWarning() should take a bilingual_str parameter.
void InitWarning(const std::string& str);

/** Show error message **/
bool InitError(const std::string& str);
bool InitError(const bilingual_str& str);

extern CClientUIInterface uiInterface;

Expand Down
6 changes: 3 additions & 3 deletions src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool WalletInit::ParameterInteraction() const

if (gArgs.GetBoolArg("-salvagewallet", false)) {
if (is_multiwallet) {
return InitError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet"));
return InitError(strprintf(Untranslated("%s is only allowed with a single wallet file"), "-salvagewallet"));
}
// Rewrite just private keys: rescan to find transactions
if (gArgs.SoftSetBoolArg("-rescan", true)) {
Expand All @@ -108,15 +108,15 @@ bool WalletInit::ParameterInteraction() const
// -zapwallettxes implies a rescan
if (zapwallettxes) {
if (is_multiwallet) {
return InitError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
return InitError(strprintf(Untranslated("%s is only allowed with a single wallet file"), "-zapwallettxes"));
}
if (gArgs.SoftSetBoolArg("-rescan", true)) {
LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -rescan=1\n", __func__);
}
}

if (gArgs.GetBoolArg("-sysperms", false))
return InitError("-sysperms is not allowed in combination with enabled wallet functionality");
return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));

return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/wallet/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
// The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
if (error || !fs::exists(wallet_dir)) {
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist").translated, wallet_dir.string()));
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
return false;
} else if (!fs::is_directory(wallet_dir)) {
chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory").translated, wallet_dir.string()));
chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), wallet_dir.string()));
return false;
// The canonical path transforms relative paths into absolute ones, so we check the non-canonical version
} else if (!wallet_dir.is_absolute()) {
chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path").translated, wallet_dir.string()));
chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
return false;
}
gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string());
Expand All @@ -49,7 +49,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
WalletLocation location(wallet_file);

if (!wallet_paths.insert(location.GetPath()).second) {
chain.initError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified.").translated, wallet_file));
chain.initError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
return false;
}

Expand All @@ -58,7 +58,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warnings);
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
if (!verify_success) {
chain.initError(error_string.translated);
chain.initError(error_string);
return false;
}
}
Expand All @@ -75,14 +75,14 @@ bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& walle
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
if (!pwallet) {
chain.initError(error.translated);
chain.initError(error);
return false;
}
AddWallet(pwallet);
}
return true;
} catch (const std::runtime_error& e) {
chain.initError(e.what());
chain.initError(Untranslated(e.what()));
return false;
}
}
Expand Down

0 comments on commit 7e923d4

Please sign in to comment.