diff --git a/hledger-lib/Hledger/Query.hs b/hledger-lib/Hledger/Query.hs index 658aa6cf3..ac58d018f 100644 --- a/hledger-lib/Hledger/Query.hs +++ b/hledger-lib/Hledger/Query.hs @@ -256,7 +256,11 @@ parseQueryTerm _ ('s':'t':'a':'t':'u':'s':':':s) = parseQueryTerm _ ('r':'e':'a':'l':':':s) = Left $ Real $ parseBool s || null s parseQueryTerm _ ('a':'m':'t':':':s) = Left $ Amt ord q where (ord, q) = parseAmountQueryTerm s parseQueryTerm _ ('e':'m':'p':'t':'y':':':s) = Left $ Empty $ parseBool s -parseQueryTerm _ ('d':'e':'p':'t':'h':':':s) = Left $ Depth $ readDef 0 s +parseQueryTerm _ ('d':'e':'p':'t':'h':':':s) + | n >= 0 = Left $ Depth n + | otherwise = error' "depth: should have a positive number" + where n = readDef 0 s + parseQueryTerm _ ('c':'u':'r':':':s) = Left $ Sym s -- support cur: as an alias parseQueryTerm _ ('t':'a':'g':':':s) = Left $ Tag n v where (n,v) = parseTag s parseQueryTerm _ "" = Left $ Any diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index b2cc930db..5c0efea2b 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -162,7 +162,10 @@ rawOptsToReportOpts rawopts = checkReportOpts <$> do -- | Do extra validation of opts, raising an error if there is trouble. checkReportOpts :: ReportOpts -> ReportOpts checkReportOpts ropts@ReportOpts{..} = - ropts + either optserror (const ropts) $ do + case depth_ of + Just d | d < 0 -> Left "--depth should have a positive number" + _ -> Right () accountlistmodeopt :: RawOpts -> AccountListMode accountlistmodeopt rawopts =