diff options
| author | Bitflash <btf01@proton.me> | 2026-08-04 10:13:41 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-04 10:13:41 -0300 |
| commit | 530f91910a4eceb6705d1212fa0e3ebe8418c6a3 (patch) | |
| tree | e8834760736e765178413c5925f56293888fbf15 /src/db.cpp | |
| parent | 1db5f372c36eb701602a70a358de2344726ed734 (diff) | |
gui: say why the wallet would not open, where the user can see it (#136)
Every fatal startup path wrote to stderr and to printf, and on Windows
neither reaches anybody. printf is remapped to OutputDebugStringF, so it
lands in debug.log inside the data directory. A -mwindows binary started
by double-clicking has no stderr at all, and AttachTerminal() cannot
help: it attaches to a parent console, which a double-clicked exe does
not have.
So Bitflash exited silently. Someone whose wallet.dat needs a newer
build -- exactly what the wallet format guard was added to tell them --
double-clicked and watched nothing happen. The guard was correct and
mute, which is the failure it was written to prevent.
Fatal startup errors now go through one reporter: debug.log as before,
stderr as before, and a message box when there is a person in front of
the screen. Applied to the three that mean "your data will not open":
the block index failing to load, the block index throwing, and
wallet.dat failing or throwing.
The box is deliberately not shown for a headless node. Those run under
scheduled tasks and services, where a modal dialog waits forever for a
click nobody is there to make -- a hung process instead of an exit code.
Headless keeps stderr and the log.
LoadWallet() now also reports why it refused, in a sentence, instead of
only logging it. The unsupported-format case is the one that has to be
understood by whoever reads it, and "LoadWallet failed" is not that.
Verified by breaking a throwaway wallet on purpose and starting both
ways. Headless: exit code 1, no dialog, no process left behind. Windowed
with no console: a box naming the file, the Berkeley DB error, the usual
cause, and where to look for more.
Diffstat (limited to 'src/db.cpp')
| -rw-r--r-- | src/db.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
| @@ -48,6 +48,10 @@ private: | |||
| 48 | 48 | ||
| 49 | static CCriticalSection cs_db; | 49 | static CCriticalSection cs_db; |
| 50 | static bool fDbEnvInit = false; | 50 | static bool fDbEnvInit = false; |
| 51 | |||
| 52 | // Why LoadWallet() refused, in words meant for the person who has to act on it. | ||
| 53 | // Empty unless the reason is one we can name. | ||
| 54 | string strWalletLoadError; | ||
| 51 | DbEnv dbenv(0u); | 55 | DbEnv dbenv(0u); |
| 52 | static map<string, int> mapFileUseCount; | 56 | static map<string, int> mapFileUseCount; |
| 53 | 57 | ||
| @@ -625,6 +629,7 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet) | |||
| 625 | bool fHaveStoredMineMode = false; | 629 | bool fHaveStoredMineMode = false; |
| 626 | bool fHaveStoredHDCoinType = false; | 630 | bool fHaveStoredHDCoinType = false; |
| 627 | vchDefaultKeyRet.clear(); | 631 | vchDefaultKeyRet.clear(); |
| 632 | strWalletLoadError.clear(); | ||
| 628 | 633 | ||
| 629 | // Satoshi's "todo: shouldn't we catch exceptions" sat here since 2009, and | 634 | // Satoshi's "todo: shouldn't we catch exceptions" sat here since 2009, and |
| 630 | // it was not a nicety. Nothing on this path caught anything, so a record | 635 | // it was not a nicety. Nothing on this path caught anything, so a record |
| @@ -779,11 +784,15 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet) | |||
| 779 | ssValue >> nMinVersion; | 784 | ssValue >> nMinVersion; |
| 780 | if (nMinVersion > WALLET_FORMAT_SUPPORTED) | 785 | if (nMinVersion > WALLET_FORMAT_SUPPORTED) |
| 781 | { | 786 | { |
| 782 | printf("LoadWallet: wallet.dat requires wallet format %d, " | 787 | // Said out loud, not only into debug.log: this is the one |
| 783 | "but this build only supports format %d\n", | 788 | // refusal whose whole purpose is to be understood, and the |
| 784 | nMinVersion, WALLET_FORMAT_SUPPORTED); | 789 | // caller puts it in front of the user. |
| 785 | printf("LoadWallet: the file was left untouched. Upgrade " | 790 | strWalletLoadError = strprintf( |
| 786 | "Bitflash before opening this wallet.\n"); | 791 | "This wallet.dat was written by a newer version of Bitflash " |
| 792 | "(wallet format %d; this build understands %d). Upgrade " | ||
| 793 | "Bitflash before opening it.", | ||
| 794 | nMinVersion, WALLET_FORMAT_SUPPORTED); | ||
| 795 | printf("LoadWallet: %s\n", strWalletLoadError.c_str()); | ||
| 787 | return false; | 796 | return false; |
| 788 | } | 797 | } |
| 789 | } | 798 | } |