From 400e5bf29680b79be8b6f31789bb354c23ac52a2 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 9 Mar 2010 18:36:27 +0000 Subject: [PATCH] web: show a proper error for a bad date in add form (#17) --- Commands/Web.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Commands/Web.hs b/Commands/Web.hs index b567607c1..86c90ffc4 100644 --- a/Commands/Web.hs +++ b/Commands/Web.hs @@ -327,8 +327,11 @@ handleAddform l = do validateAmt2 _ = [] amt1' = either (const missingamt) id $ parse someamount "" amt1 amt2' = either (const missingamt) id $ parse someamount "" amt2 + (date', dateparseerr) = case fixSmartDateStrEither today date of + Right d -> (d, []) + Left e -> ("1900/01/01", [showDateParseError e]) t = Transaction { - tdate = parsedate $ fixSmartDateStr today date + tdate = parsedate date' -- date' must be parseable ,teffectivedate=Nothing ,tstatus=False ,tcode="" @@ -340,17 +343,19 @@ handleAddform l = do ] ,tpreceding_comment_lines="" } - (t', berr) = case balanceTransaction t of + (t', balanceerr) = case balanceTransaction t of Right t'' -> (t'', []) - Left e -> (t, [e]) + Left e -> (t, [head $ lines e]) -- show just the error not the transaction errs = concat [ validateDate date + ,dateparseerr ,validateDesc desc ,validateAcct1 acct1 ,validateAmt1 amt1 ,validateAcct2 acct2 ,validateAmt2 amt2 - ] ++ berr + ,balanceerr + ] in case null errs of False -> Failure errs