show better errors for unbalanced transaction and missing default year

This commit is contained in:
Simon Michael 2009-06-05 19:35:12 +00:00
parent 00ad42e629
commit d1418a2a21
2 changed files with 5 additions and 3 deletions

View File

@ -313,7 +313,7 @@ ledgerTransaction = do
let t = LedgerTransaction date status code description comment postings ""
case balanceLedgerTransaction t of
Right t' -> return t'
Left err -> error err
Left err -> fail err
ledgerdate :: GenParser Char LedgerFileCtx Day
ledgerdate = try ledgerfulldate <|> ledgerpartialdate
@ -331,7 +331,7 @@ ledgerpartialdate = do
(_,m,d) <- md
many spacenonewline
y <- getYear
when (y==Nothing) $ error "partial date found, but no default year specified"
when (y==Nothing) $ fail "partial date found, but no default year specified"
return $ fromGregorian (fromJust y) (read m) (read d)
ledgerdatetime :: GenParser Char LedgerFileCtx LocalTime

View File

@ -84,7 +84,9 @@ $ hledger -f sample.ledger balance --depth 1
{-
@
$ printf "2009/1/1 a\n b 1.1\n c -1\n" | runhaskell hledger.hs -f- reg 2>&1 ; true
hledger.hs: could not balance this transaction, amounts do not add up to zero:
"-" (line 4, column 1):
unexpected end of input
could not balance this transaction, amounts do not add up to zero:
2009/01/01 a
b 1.1
c -1