Skip to content

Commit

Permalink
web: don't hang when reloading the file, eg after adding a transaction (
Browse files Browse the repository at this point in the history
#1409)

This was caused by an circular reference in an untested code path
in getViewData, added some months ago (lines 211-212 in 260283e:
"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.
  • Loading branch information
simonmichael committed Dec 7, 2020
1 parent fa28b43 commit 69edf90
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions hledger-web/Hledger/Web/Foundation.hs
Expand Up @@ -205,17 +205,14 @@ instance Show Text.Blaze.Markup where show _ = "<blaze markup>"
-- | 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
Expand Down

0 comments on commit 69edf90

Please sign in to comment.