From 563b2a60d6a371f26474410397da435547e58786 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Thu, 30 Nov 2023 16:00:08 -0500 Subject: [PATCH] wallet: Better error message when missing LegacySPKM during migration --- src/wallet/wallet.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 437b274cefd..b260e409e57 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3862,7 +3862,11 @@ std::optional CWallet::GetDescriptorsForLegacy(bilingual_str& err AssertLockHeld(cs_wallet); LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan(); - assert(legacy_spkm); + if (!Assume(legacy_spkm)) { + // This shouldn't happen + error = Untranslated(STR_INTERNAL_BUG("Error: Legacy wallet data missing")); + return std::nullopt; + } std::optional res = legacy_spkm->MigrateToDescriptor(); if (res == std::nullopt) { @@ -3877,8 +3881,9 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error) AssertLockHeld(cs_wallet); LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan(); - if (!legacy_spkm) { - error = _("Error: This wallet is already a descriptor wallet"); + if (!Assume(legacy_spkm)) { + // This shouldn't happen + error = Untranslated(STR_INTERNAL_BUG("Error: Legacy wallet data missing")); return false; }