Prettify option parsing errors (#478)
Megaparsec's show instance for ParseError doesn't produce digestible strings. parseErrorPretty has to be used instead.
This commit is contained in:
		
							parent
							
								
									b0e907e5a4
								
							
						
					
					
						commit
						dfbb683573
					
				| @ -41,6 +41,7 @@ import Data.Time.Calendar | |||||||
| import Data.Default | import Data.Default | ||||||
| import Safe | import Safe | ||||||
| import Test.HUnit | import Test.HUnit | ||||||
|  | import Text.Megaparsec.Error | ||||||
| 
 | 
 | ||||||
| import Hledger.Data | import Hledger.Data | ||||||
| import Hledger.Query | import Hledger.Query | ||||||
| @ -207,11 +208,11 @@ beginDatesFromRawOpts d = catMaybes . map (begindatefromrawopt d) | |||||||
|   where |   where | ||||||
|     begindatefromrawopt d (n,v) |     begindatefromrawopt d (n,v) | ||||||
|       | n == "begin" = |       | n == "begin" = | ||||||
|           either (\e -> optserror $ "could not parse "++n++" date: "++show e) Just $ |           either (\e -> optserror $ "could not parse "++n++" date: "++parseErrorPretty e) Just $ | ||||||
|           fixSmartDateStrEither' d (T.pack v) |           fixSmartDateStrEither' d (T.pack v) | ||||||
|       | n == "period" = |       | n == "period" = | ||||||
|         case |         case | ||||||
|           either (\e -> optserror $ "could not parse period option: "++show e) id $ |           either (\e -> optserror $ "could not parse period option: "++parseErrorPretty e) id $ | ||||||
|           parsePeriodExpr d (stripquotes $ T.pack v) |           parsePeriodExpr d (stripquotes $ T.pack v) | ||||||
|         of |         of | ||||||
|           (_, DateSpan (Just b) _) -> Just b |           (_, DateSpan (Just b) _) -> Just b | ||||||
| @ -225,11 +226,11 @@ endDatesFromRawOpts d = catMaybes . map (enddatefromrawopt d) | |||||||
|   where |   where | ||||||
|     enddatefromrawopt d (n,v) |     enddatefromrawopt d (n,v) | ||||||
|       | n == "end" = |       | n == "end" = | ||||||
|           either (\e -> optserror $ "could not parse "++n++" date: "++show e) Just $ |           either (\e -> optserror $ "could not parse "++n++" date: "++parseErrorPretty e) Just $ | ||||||
|           fixSmartDateStrEither' d (T.pack v) |           fixSmartDateStrEither' d (T.pack v) | ||||||
|       | n == "period" = |       | n == "period" = | ||||||
|         case |         case | ||||||
|           either (\e -> optserror $ "could not parse period option: "++show e) id $ |           either (\e -> optserror $ "could not parse period option: "++parseErrorPretty e) id $ | ||||||
|           parsePeriodExpr d (stripquotes $ T.pack v) |           parsePeriodExpr d (stripquotes $ T.pack v) | ||||||
|         of |         of | ||||||
|           (_, DateSpan _ (Just e)) -> Just e |           (_, DateSpan _ (Just e)) -> Just e | ||||||
| @ -243,7 +244,7 @@ intervalFromRawOpts = lastDef NoInterval . catMaybes . map intervalfromrawopt | |||||||
|   where |   where | ||||||
|     intervalfromrawopt (n,v) |     intervalfromrawopt (n,v) | ||||||
|       | n == "period" = |       | n == "period" = | ||||||
|           either (\e -> optserror $ "could not parse period option: "++show e) (Just . fst) $ |           either (\e -> optserror $ "could not parse period option: "++parseErrorPretty e) (Just . fst) $ | ||||||
|           parsePeriodExpr nulldate (stripquotes $ T.pack v) -- reference date does not affect the interval |           parsePeriodExpr nulldate (stripquotes $ T.pack v) -- reference date does not affect the interval | ||||||
|       | n == "daily"     = Just $ Days 1 |       | n == "daily"     = Just $ Days 1 | ||||||
|       | n == "weekly"    = Just $ Weeks 1 |       | n == "weekly"    = Just $ Weeks 1 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user