From 2e3fd090ff76039a1d69ccbdb11361b7234df9de Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 1 Dec 2025 20:16:18 +0800 Subject: [PATCH] [gnc-autoclear.cpp] restore abort explanation message --- libgnucash/app-utils/gnc-autoclear.cpp | 13 +++++++++---- libgnucash/app-utils/test/test-autoclear.cpp | 12 ++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libgnucash/app-utils/gnc-autoclear.cpp b/libgnucash/app-utils/gnc-autoclear.cpp index 11fd4d58a4..ae6eee4374 100644 --- a/libgnucash/app-utils/gnc-autoclear.cpp +++ b/libgnucash/app-utils/gnc-autoclear.cpp @@ -79,7 +79,7 @@ using SplitVec = std::vector; struct Solution { - bool abort = false; + std::optional abort; SplitVec splits; }; @@ -124,7 +124,7 @@ subset_sum (SplitInfoVec::const_iterator iter, DEBUG ("SOLUTION FOUND: %s%s", path_to_str (path), solution.splits.empty() ? "" : " ABORT: AMBIGUOUS"); if (!solution.splits.empty()) - solution.abort = true; + solution.abort = "Cannot uniquely clear splits. Found multiple possibilities."; else { solution.splits.resize (path.size()); @@ -140,7 +140,7 @@ subset_sum (SplitInfoVec::const_iterator iter, if (monitor.should_abort()) { DEBUG ("ABORT: timeout"); - solution.abort = true; + solution.abort = "Auto-clear exceeds allocated time"; return; } @@ -227,12 +227,17 @@ gnc_account_get_autoclear_splits (Account *account, gnc_numeric toclear_value, DEBUG ("finished subset_sum in %f seconds", monitor.get_elapsed()); - if (solution.splits.empty() || solution.abort) + if (solution.splits.empty()) { g_set_error (error, autoclear_quark, 1, "%s", "The selected amount cannot be cleared."); return nullptr; } + else if (solution.abort) + { + g_set_error (error, autoclear_quark, 1, "%s", *solution.abort); + return nullptr; + } return std::accumulate (solution.splits.begin(), solution.splits.end(), diff --git a/libgnucash/app-utils/test/test-autoclear.cpp b/libgnucash/app-utils/test/test-autoclear.cpp index b9ee6d9a85..c21ba693ae 100644 --- a/libgnucash/app-utils/test/test-autoclear.cpp +++ b/libgnucash/app-utils/test/test-autoclear.cpp @@ -102,8 +102,8 @@ TestCase ambiguousTestCase = { { "Memo 03", -10, false }, }, .tests = { - { -10, "The selected amount cannot be cleared." }, - { -20, "The selected amount cannot be cleared." }, + { -10, "Cannot uniquely clear splits. Found multiple possibilities." }, + { -20, "Cannot uniquely clear splits. Found multiple possibilities." }, // -30 can be cleared by returning all three -10 splits { -30, nullptr }, @@ -121,7 +121,7 @@ TestCase sequentialTestCase1 = .tests = { { 1, "The selected amount cannot be cleared." }, { 4, "The selected amount cannot be cleared." }, - { 5, "The selected amount cannot be cleared." }, + { 5, "Cannot uniquely clear splits. Found multiple possibilities." }, { 6, "The selected amount cannot be cleared." }, { 9, "The selected amount cannot be cleared." }, { 11, "The selected amount cannot be cleared." }, @@ -156,9 +156,9 @@ TestCase sequentialTestCase3 = { "Memo 04", 5, false }, }, .tests = { - { 5, "The selected amount cannot be cleared." }, - { 7, "The selected amount cannot be cleared." }, - { 10, "The selected amount cannot be cleared." }, + { 5, "Cannot uniquely clear splits. Found multiple possibilities." }, + { 7, "Cannot uniquely clear splits. Found multiple possibilities." }, + { 10, "Cannot uniquely clear splits. Found multiple possibilities." }, { 2, nullptr }, { 12, nullptr }, { 15, nullptr },