Skip to content

Commit 09e2078

Browse files
committed
fix: make a few more error messages consistent, hiding call stack [#2367]
1 parent 18eb132 commit 09e2078

File tree

18 files changed

+29
-27
lines changed

18 files changed

+29
-27
lines changed

hledger-lib/Hledger/Data/Amount.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ import Test.Tasty (testGroup)
196196
import Test.Tasty.HUnit ((@?=), assertBool, testCase)
197197

198198
import Hledger.Data.Types
199-
import Hledger.Utils (colorB, numDigitsInt, numDigitsInteger)
199+
import Hledger.Utils (colorB, error', numDigitsInt, numDigitsInteger)
200200
import Hledger.Utils.Text (textQuoteIfNeeded)
201201
import Text.WideString (WideBuilder(..), wbFromText, wbToText, wbUnpack)
202202
import Data.Functor ((<&>))
@@ -333,7 +333,7 @@ similarAmountsOp op Amount{acommodity=_, aquantity=q1, astyle=AmountStyle{aspre
333333
-- trace ("a1:"++showAmountDebug a1) $ trace ("a2:"++showAmountDebug a2) $ traceWith (("= :"++).showAmountDebug)
334334
nullamt{acommodity=c2, aquantity=q1 `op` q2, astyle=s2{asprecision=max p1 p2}}
335335
-- c1==c2 || q1==0 || q2==0 =
336-
-- otherwise = error "tried to do simple arithmetic with amounts in different commodities"
336+
-- otherwise = error' "tried to do simple arithmetic with amounts in different commodities"
337337

338338
-- | Convert an amount to the specified commodity, ignoring and discarding
339339
-- any costs and assuming an exchange rate of 1.
@@ -774,9 +774,9 @@ instance Num MixedAmount where
774774
fromInteger = mixedAmount . fromInteger
775775
negate = maNegate
776776
(+) = maPlus
777-
(*) = error "error, mixed amounts do not support multiplication" -- PARTIAL:
777+
(*) = error' "error, mixed amounts do not support multiplication" -- PARTIAL:
778778
abs = mapMixedAmount (\amt -> amt { aquantity = abs (aquantity amt)})
779-
signum = error "error, mixed amounts do not support signum"
779+
signum = error' "error, mixed amounts do not support signum"
780780

781781
-- | Calculate the key used to store an Amount within a MixedAmount.
782782
amountKey :: Amount -> MixedAmountKey

hledger-lib/Hledger/Data/Dates.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ dateSpanSplitLimits :: (Day -> Day) -> (Day -> Day) -> DateSpan -> (Day, Day)
285285
dateSpanSplitLimits start _ (DateSpan (Just s) (Just e)) = (start $ fromEFDay s, fromEFDay e)
286286
dateSpanSplitLimits start next (DateSpan (Just s) Nothing) = (start $ fromEFDay s, next $ start $ fromEFDay s)
287287
dateSpanSplitLimits start next (DateSpan Nothing (Just e)) = (start $ fromEFDay e, next $ start $ fromEFDay e)
288-
dateSpanSplitLimits _ _ (DateSpan Nothing Nothing) = error "dateSpanSplitLimits: should not be nulldatespan" -- PARTIAL: This case should have been handled in splitSpan
288+
dateSpanSplitLimits _ _ (DateSpan Nothing Nothing) = error' "dateSpanSplitLimits: should not be nulldatespan" -- PARTIAL: This case should have been handled in splitSpan
289289

290290
-- | Construct a list of exact 'DateSpan's from a list of boundaries, which fit within a given range.
291291
spansFromBoundaries :: Day -> [Day] -> [DateSpan]

hledger-lib/Hledger/Data/Json.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import qualified Data.Text.Lazy.Builder as TB
2828
import Text.Megaparsec (Pos, SourcePos, mkPos, unPos)
2929

3030
import Hledger.Data.Types
31+
import Hledger.Utils.IO (error')
3132
import Hledger.Data.Amount (amountsRaw, mixed)
3233

3334
-- To JSON
@@ -290,8 +291,8 @@ readJsonFile :: FromJSON a => FilePath -> IO a
290291
readJsonFile f = do
291292
bl <- BL.readFile f
292293
-- PARTIAL:
293-
let v = fromMaybe (error $ "could not decode JSON in "++show f++" to target value")
294+
let v = fromMaybe (error' $ "could not decode JSON in "++show f++" to target value")
294295
(decode bl :: Maybe Value)
295296
case fromJSON v :: FromJSON a => Result a of
296-
Error e -> error e
297+
Error e -> error' e
297298
Success t -> return t

hledger-lib/Hledger/Query.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ parseQueryTerm _ (T.stripPrefix "status:" -> Just s) =
309309
case parseStatus s of Left e -> Left $ "\"status:"++T.unpack s++"\" gave a parse error: " ++ e
310310
Right st -> Right (StatusQ st, [])
311311
parseQueryTerm _ (T.stripPrefix "real:" -> Just s) = Right (Real $ parseBool s || T.null s, [])
312-
parseQueryTerm _ (T.stripPrefix "amt:" -> Just s) = Right (Amt ord q, []) where (ord, q) = either error id $ parseAmountQueryTerm s -- PARTIAL:
312+
parseQueryTerm _ (T.stripPrefix "amt:" -> Just s) = Right (Amt ord q, []) where (ord, q) = either error' id $ parseAmountQueryTerm s -- PARTIAL:
313313
parseQueryTerm _ (T.stripPrefix "depth:" -> Just s) = (,[]) <$> parseDepthSpecQuery s
314314
parseQueryTerm _ (T.stripPrefix "cur:" -> Just s) = (,[]) . Sym <$> toRegexCI ("^" <> s <> "$") -- support cur: as an alias
315315
parseQueryTerm _ (T.stripPrefix "tag:" -> Just s) = (,[]) <$> parseTag s

hledger-lib/Hledger/Reports/PostingsReport.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ postingsReport rspec@ReportSpec{_rsReportOpts=ropts@ReportOpts{..}} j = items
106106
runningcalc = registerRunningCalculationFn ropts
107107
startnum = if historical then length precedingps + 1 else 1
108108
postings | historical = if sortspec_ /= defsortspec
109-
then error "--historical and --sort should not be used together"
109+
then error' "--historical and --sort should not be used together"
110110
else sortedps
111111
| otherwise = sortedps
112112

hledger-lib/Hledger/Reports/ReportOptions.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ journalApplyValuationFromOptsWith rspec@ReportSpec{_rsReportOpts=ropts} j priceo
643643
historical = DateSpan Nothing $ (fmap Exact . spanStart) =<< headMay spans
644644
spans = snd $ reportSpanBothDates j rspec
645645
styles = journalCommodityStyles j
646-
err = error "journalApplyValuationFromOpts: expected all spans to have an end date"
646+
err = error' "journalApplyValuationFromOpts: expected all spans to have an end date"
647647

648648
-- | Select the Account valuation functions required for performing valuation after summing
649649
-- amounts. Used in MultiBalanceReport to value historical and similar reports.
@@ -662,7 +662,7 @@ mixedAmountApplyValuationAfterSumFromOptsWith ropts j priceoracle =
662662
NoConversionOp -> id
663663
ToCost -> styleAmounts styles . mixedAmountCost
664664
styles = journalCommodityStyles j
665-
err = error "mixedAmountApplyValuationAfterSumFromOptsWith: expected all spans to have an end date"
665+
err = error' "mixedAmountApplyValuationAfterSumFromOptsWith: expected all spans to have an end date"
666666

667667
-- | If the ReportOpts specify that we are performing valuation after summing amounts,
668668
-- return Just of the commodity symbol we're converting to, Just Nothing for the default,

hledger-lib/Hledger/Utils/String.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,5 @@ strWidth = realLength
243243
stripAnsi :: String -> String
244244
stripAnsi s = either err id $ regexReplace ansire "" s
245245
where
246-
err = error "stripAnsi: invalid replacement pattern" -- PARTIAL, shouldn't happen
246+
err = errorWithoutStackTrace "stripAnsi: invalid replacement pattern" -- PARTIAL, shouldn't happen
247247
ansire = toRegex' $ T.pack "\ESC\\[([0-9]+;)*([0-9]+)?[ABCDHJKfmsu]" -- PARTIAL, should succeed

hledger-ui/Hledger/UI/ErrorScreen.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ esDraw UIState{aScreen=ES ESS{..}
6363
,("q", "quit")
6464
]
6565

66-
esDraw _ = error "draw function called with wrong screen type, should not happen" -- PARTIAL:
66+
esDraw _ = error' "draw function called with wrong screen type, should not happen" -- PARTIAL:
6767

6868
esHandle :: BrickEvent Name AppEvent -> EventM Name UIState ()
6969
esHandle ev = do

hledger-ui/Hledger/UI/TransactionScreen.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ tsHandle ev = do
152152
liftIO (uiReloadJournal copts d ui) >>= put'
153153
-- debugging.. leaving these here because they were hard to find
154154
-- \u -> dbguiEv (pshow u) >> put' u -- doesn't log
155-
-- \UIState{aScreen=TS tss} -> error $ pshow $ _tssTransaction tss
155+
-- \UIState{aScreen=TS tss} -> error' $ pshow $ _tssTransaction tss
156156

157157
VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
158158

hledger-ui/Hledger/UI/UIScreens.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ asUpdateHelper rspec0 d copts roptsModify extraquery j ass = dbgui "asUpdateHelp
140140
updateReportSpec
141141
ropts
142142
rspec0{_rsDay=d} -- update to the current date, might have changed since program start
143-
& either (error "asUpdateHelper: adjusting the query, should not have failed") id -- PARTIAL:
143+
& either (error' "asUpdateHelper: adjusting the query, should not have failed") id -- PARTIAL:
144144
& reportSpecSetFutureAndForecast (forecast_ $ inputopts_ copts) -- include/exclude future & forecast transactions
145145
& reportSpecAddQuery extraquery -- add any extra restrictions
146146

@@ -265,7 +265,7 @@ rsUpdate uopts d j rss@RSS{_rssAccount, _rssForceInclusive, _rssList=oldlist} =
265265
}
266266
rspec' =
267267
updateReportSpec ropts' rspec{_rsDay=d}
268-
& either (error "rsUpdate: adjusting the query for register, should not have failed") id -- PARTIAL:
268+
& either (error' "rsUpdate: adjusting the query for register, should not have failed") id -- PARTIAL:
269269
& reportSpecSetFutureAndForecast (forecast_ $ inputopts_ copts)
270270

271271
-- gather transactions to display

hledger-ui/Hledger/UI/UIState.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ enableForecastPreservingPeriod ui copts = set forecast mforecast copts
219219
-- | Toggle between showing all and showing only real (non-virtual) items.
220220
toggleReal :: UIState -> UIState
221221
toggleReal = fromRight err . overEither real not -- PARTIAL:
222-
where err = error "toggleReal: updating Real should not result in an error"
222+
where err = error' "toggleReal: updating Real should not result in an error"
223223

224224
-- | Toggle the ignoring of balance assertions.
225225
toggleIgnoreBalanceAssertions :: UIState -> UIState
@@ -263,7 +263,7 @@ setReportPeriod p = updateReportPeriod (const p)
263263
-- | Update report period by a applying a function.
264264
updateReportPeriod :: (Period -> Period) -> UIState -> UIState
265265
updateReportPeriod updatePeriod = fromRight err . overEither period updatePeriod -- PARTIAL:
266-
where err = error "updateReportPeriod: updating period should not result in an error"
266+
where err = error' "updateReportPeriod: updating period should not result in an error"
267267

268268
-- | Apply a new filter query, or return the failing query.
269269
setFilter :: String -> UIState -> Either String UIState
@@ -318,7 +318,7 @@ getDepth = dsFlatDepth . (^.depth)
318318
updateReportDepth :: (DepthSpec -> DepthSpec) -> UIState -> UIState
319319
updateReportDepth updateDepth ui = over reportSpec update ui
320320
where
321-
update = fromRight (error "updateReportDepth: updating depth should not result in an error") -- PARTIAL:
321+
update = fromRight (error' "updateReportDepth: updating depth should not result in an error") -- PARTIAL:
322322
. updateReportSpecWith (\ropts -> ropts{depth_=clipDepth ropts $ updateDepth (depth_ ropts)})
323323
clipDepth _ (DepthSpec Nothing _) = mempty
324324
clipDepth ropts ds@(DepthSpec (Just d) _) | d < 0 = depth_ ropts

hledger-web/Hledger/Web/Handler/RegisterR.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ undecorateLinks xs0@(x:_) =
9393
let (link, xs1) = span (isJust . fst) xs0
9494
(comma, xs2) = span (isNothing . fst) xs1
9595
in (acct, (map snd link, map snd comma)) : undecorateLinks xs2
96-
_ -> error "link name not decorated with account" -- PARTIAL:
96+
_ -> error' "link name not decorated with account" -- PARTIAL:
9797

9898
decorateLinks :: [(acct, ([char], [char]))] -> [(Maybe acct, char)]
9999
decorateLinks = concatMap $ \(acct, (name, comma)) ->

hledger-web/Hledger/Web/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ web opts j = do
161161
when (isSocket sockstat) $ removeFile s
162162
)
163163
(\sock -> Network.Wai.Handler.Warp.runSettingsSocket warpsettings sock app)
164-
else error $ unlines
164+
else error' $ unlines
165165
["Unix domain sockets are not available on your operating system."
166166
,"Please try again without --socket."
167167
]

hledger-web/Hledger/Web/Test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ hledgerWebTest = do
136136
," assets 10"
137137
," income"
138138
])
139-
j <- fmap (either error id) . runExceptT $ journalFinalise iopts f "" pj -- PARTIAL: journalFinalise should not fail
139+
j <- fmap (either error' id) . runExceptT $ journalFinalise iopts f "" pj -- PARTIAL: journalFinalise should not fail
140140
runTests "hledger-web with --forecast" rawopts j $ do
141141

142142
yit "shows forecasted transactions" $ do

hledger/Hledger/Cli/Anchor.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import qualified Text.URI.QQ as UriQQ
1717

1818
import qualified Hledger.Write.Spreadsheet as Spr
1919
import Hledger.Write.Spreadsheet (headerCell)
20+
import Hledger.Utils.IO (error')
2021
import Hledger.Utils.Text (quoteIfSpaced)
2122
import Hledger.Data.Dates (showDateSpan, showDate)
2223
import Hledger.Data.Types (DateSpan)
@@ -28,7 +29,7 @@ registerQueryUrl query =
2829
[UriQQ.uri|register|] {
2930
Uri.uriQuery =
3031
[Uri.QueryParam [UriQQ.queryKey|q|] $
31-
fromMaybe (error "register URI query construction failed") $
32+
fromMaybe (error' "register URI query construction failed") $
3233
Uri.mkQueryValue $ Text.unwords $
3334
map quoteIfSpaced $ filter (not . Text.null) query]
3435
}

hledger/Hledger/Cli/Commands/Activity.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ showHistogram rspec@ReportSpec{_rsQuery=q} j =
4444
ps = sortOn postingDate $ filter (q `matchesPosting`) $ journalPostings j
4545

4646
printDayWith f (DateSpan (Just b) _, ps) = printf "%s %s\n" (show $ fromEFDay b) (f ps)
47-
printDayWith _ _ = error "Expected start date for DateSpan" -- PARTIAL:
47+
printDayWith _ _ = error' "Expected start date for DateSpan" -- PARTIAL:
4848

4949
countBar ps = replicate (length ps) barchar

hledger/Hledger/Cli/Commands/Add.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ getAndAddTransactions es@EntryState{..} = (do
121121
let defaultPrevInput = PrevInput{prevDateAndCode=Nothing, prevDescAndCmnt=Nothing, prevAccount=[], prevAmountAndCmnt=[]}
122122
mt <- runInputT (setComplete noCompletion defaultSettings) (System.Console.Wizard.run $ haskeline $ confirmedTransactionWizard defaultPrevInput es [])
123123
case mt of
124-
Nothing -> error "Could not interpret the input, restarting" -- caught below causing a restart, I believe -- PARTIAL:
124+
Nothing -> error' "Could not interpret the input, restarting" -- caught below causing a restart, I believe -- PARTIAL:
125125
Just t -> do
126126
j <- if debug_ esOpts > 0
127127
then do hPutStrLn stderr "Skipping journal add due to debug mode."

hledger/Hledger/Cli/Commands/Roi.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ roi CliOpts{rawopts_=rawopts, reportspec_=rspec@ReportSpec{_rsReportOpts=ReportO
9696

9797
let (fullPeriod, spans) = reportSpan filteredj rspec
9898

99-
let processSpan (DateSpan Nothing _) = error "Undefined start of the period - will be unable to compute the rates of return"
100-
processSpan (DateSpan _ Nothing) = error "Undefined end of the period - will be unable to compute the rates of return"
99+
let processSpan (DateSpan Nothing _) = error' "Undefined start of the period - will be unable to compute the rates of return"
100+
processSpan (DateSpan _ Nothing) = error' "Undefined end of the period - will be unable to compute the rates of return"
101101
processSpan spn@(DateSpan (Just begin) (Just end)) = do
102102
-- Spans are [begin,end), and end is 1 day after the actual end date we are interested in
103103
let

0 commit comments

Comments
 (0)