hledger icon indicating copy to clipboard operation
hledger copied to clipboard

better hledger-web first startup experience

Open simonmichael opened this issue 5 years ago β€’ 7 comments

Reported on list today: hledger-web fails to start when no journal file exists yet. And if you have started it by clicking icons you won’t know why. We should provide a better startup experience.

simonmichael avatar Jul 31 '18 21:07 simonmichael

@simonmichael I'm trying to dip my toes into this issue but I'm encountering some unexpected friction.

I was about to refactor the withJournalDo to add a exceptional handler (something like withJournalDoOrElse :: CliOpts -> (Journal -> IO a) -> IO a -> IO a) when the journal did not exist, or coudn't be parsed. But that would cascade in a refactor of readJournalFile, readJournalFile up until requireJournalFileExists which yeilds just a IO (); not something that can be catched.

So I opted to re-validate the doesFileExist before withJournalDo on the hledgerWebMain. This double-checking of the journal existence is a tad redundant, but I felt it was less intrusive than creating a whole new branch of withJournalDoOrElse. This path was not without its own friction. It started to make hard to spool the yesod application, as both paths would need a lot of the same config (eg. the host and port) but it is not so easily extracted.

I did a very quick try to change the makeApplication to consume a Maybe Journal but the code started to spaghetti out of control πŸ˜….

When you wrote this issue, did you have any clear idea how you would want the code to look like? I'll keep trying things out πŸ˜„

jazcarate avatar Oct 31 '21 18:10 jazcarate

I did not! Thanks for looking at it. We should probably think about the desired user experience too. This issue primarily matters on Windows I guess.

simonmichael avatar Oct 31 '21 19:10 simonmichael

Ok, so a bit of tinkering, I reached a possible solution. Rather than decouple the Journal from the app; have another Yesod application entirely that has only the error string, and display this web application with a single route when something goes wrong.

There is a draft in https://github.com/simonmichael/hledger/pull/1753 with a couple of open questions. Let me know if this is a sensible approach; or I should reconsider.

jazcarate avatar Nov 14 '21 13:11 jazcarate

@jazcarate that's clever. What about just automatically creating an empty journal file in the default place when it's unspecified and nonexistent ? At least for hledger-web, possibly for hledger/hledger-ui as well ? Any significant downsides ?

simonmichael avatar Nov 14 '21 16:11 simonmichael

πŸ€” This is the third time writing this comment πŸ˜…. After three successive "Aha" moments, I can't think of a downside. Though I'm not entirely sure what would be the consequences of running the web app with a nulljournal. I saw there is the capability of adding messages to the app, so I think I can route the error as a message/alert and send a nulljournal. I'll wire the web to to that and test it πŸ‘

jazcarate avatar Nov 14 '21 17:11 jazcarate

All tools should work fine with an empty journal, I'm just not sure if auto-creating the file will be problem free. Let's see.

simonmichael avatar Nov 14 '21 17:11 simonmichael

When a file is specified with -f but does not exist, we should not auto-create in that case.

simonmichael avatar Nov 14 '21 17:11 simonmichael