From 69edf9003edd59a9f2556bd00969314a32635191 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 6 Dec 2020 17:35:41 -0800 Subject: [PATCH] web: don't hang when reloading the file, eg after adding a transaction (#1409) This was caused by an circular reference in an untested code path in getViewData, added some months ago (lines 211-212 in 260283e2: "lib,cli,ui,web: Introduce ReportSpec, which holds ReportOpts, the day of the report, and the parsed Query."). This kind of bug unfortunately seems to be easy to create in Haskell, and sometimes quite tedious to track down. For this particular case, we should add a suitable test to the hledger-web test suite, and/or set up a pre-release human test script, like hledger-ui's. The bug was very obvious to the first downloader of hledger-web 1.20, but it seems over the last three months nobody used a hledger-web built from master. Providing and encouraging use of nightly builds could also help. --- hledger-web/Hledger/Web/Foundation.hs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hledger-web/Hledger/Web/Foundation.hs b/hledger-web/Hledger/Web/Foundation.hs index dfc2c771c..93ce3bc20 100644 --- a/hledger-web/Hledger/Web/Foundation.hs +++ b/hledger-web/Hledger/Web/Foundation.hs @@ -205,17 +205,14 @@ instance Show Text.Blaze.Markup where show _ = "" -- | Gather data used by handlers and templates in the current request. getViewData :: Handler ViewData getViewData = do - App {appOpts = opts, appJournal} <- getYesod + App{appOpts=opts@WebOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{rsOpts}}}, appJournal} <- getYesod today <- liftIO getCurrentDay - let copts = cliopts_ opts - rspec = (reportspec_ copts){rsOpts=ropts} - ropts = (rsOpts rspec){no_elide_ = True} -- try to read the latest journal content, keeping the old content -- if there's an error (j, mjerr) <- getCurrentJournal appJournal - copts {reportspec_ = rspec} + copts{reportspec_=rspec{rsOpts=rsOpts{no_elide_=True}}} today -- try to parse the query param, assuming no query if there's an error