From 397988503762f59201e968128aa30468dfdef4a8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 29 Nov 2010 01:14:12 +0000 Subject: [PATCH] chart: give a meaningful error message for empty journals --- hledger-chart/Hledger/Chart/Main.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hledger-chart/Hledger/Chart/Main.hs b/hledger-chart/Hledger/Chart/Main.hs index efa9b50ca..5af1bd24e 100644 --- a/hledger-chart/Hledger/Chart/Main.hs +++ b/hledger-chart/Hledger/Chart/Main.hs @@ -16,6 +16,7 @@ import Data.Colour.SRGB.Linear (rgb) import Data.List import Safe (readDef) import System.Console.GetOpt +import System.Exit (exitFailure) #if __GLASGOW_HASKELL__ <= 610 import Prelude hiding (putStr, putStrLn) import System.IO.UTF8 (putStr, putStrLn) @@ -71,12 +72,15 @@ main = do chart :: [Opt] -> [String] -> Journal -> IO () chart opts args j = do t <- getCurrentLocalTime - let chart = genPie opts (optsToFilterSpec opts args t) j - renderableToPNGFile (toRenderable chart) w h filename - return () - where - filename = getOption opts ChartOutput defchartoutput - (w,h) = parseSize $ getOption opts ChartSize defchartsize + if null $ jtxns j + then putStrLn "This journal has no transactions, can't make a chart." >> exitFailure + else do + let chart = genPie opts (optsToFilterSpec opts args t) j + renderableToPNGFile (toRenderable chart) w h filename + return () + where + filename = getOption opts ChartOutput defchartoutput + (w,h) = parseSize $ getOption opts ChartSize defchartsize -- | Extract string option value from a list of options or use the default getOption :: [Opt] -> (String->Opt) -> String -> String