From 8f6b7b202ebbff252bd297cfcdb3a11db18d4966 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 23 Dec 2023 16:40:32 -1000 Subject: [PATCH] fix: traceOrLog and a rare warning from valuation code Hledger.Utils.Debug.traceOrLog was logging when it should trace and vice versa. This affected a warning which Hledger.Data.Valuation.pricesShortestPath should display if encountering a pathologically long (>1000) price chain. Also note some oddities about that warning. --- hledger-lib/Hledger/Data/Valuation.hs | 6 ++++++ hledger-lib/Hledger/Utils/Debug.hs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Data/Valuation.hs b/hledger-lib/Hledger/Data/Valuation.hs index b52502498..6016add54 100644 --- a/hledger-lib/Hledger/Data/Valuation.hs +++ b/hledger-lib/Hledger/Data/Valuation.hs @@ -364,6 +364,12 @@ pricesShortestPath start end edges = case concatMap extend paths of [] -> Nothing _ | pathlength > maxpathlength -> + -- XXX This is unusual: + -- 1. A warning, not an error, which we usually avoid + -- 2. Not a debug message (when triggered, we always print it) + -- 3. Printed either to stdout or (eg in hledger-ui) to the debug log file. + -- This is the only place we use traceOrLog like this. + -- Also before 1.32.2, traceOrLog was doing the opposite of what it should [#2134]. traceOrLog ("gave up searching for a price chain at length "++show maxpathlength++", please report a bug") Nothing where diff --git a/hledger-lib/Hledger/Utils/Debug.hs b/hledger-lib/Hledger/Utils/Debug.hs index ad5b1f524..44fe545a3 100644 --- a/hledger-lib/Hledger/Utils/Debug.hs +++ b/hledger-lib/Hledger/Utils/Debug.hs @@ -332,7 +332,7 @@ ptraceLogAtIO level label a = -- | Trace or log a string depending on shouldLog, -- before returning the second argument. traceOrLog :: String -> a -> a -traceOrLog = if shouldLog then trace else traceLog +traceOrLog = if shouldLog then traceLog else trace -- | Trace or log a string depending on shouldLog, -- when global debug level is at or above the specified level,