| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Data.Errors
Description
Helpers for making error messages.
Synopsis
- decorateExcerpt :: Int -> Maybe (Int, Maybe Int) -> Text -> Text
- makeAccountTagErrorExcerpt :: (AccountName, AccountDeclarationInfo) -> TagName -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makeCommodityTagErrorExcerpt :: Commodity -> TagName -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makePriceDirectiveErrorExcerpt :: PriceDirective -> Maybe (PriceDirective -> Text -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makeTransactionErrorExcerpt :: Transaction -> (Transaction -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makePostingErrorExcerpt :: Posting -> (Posting -> Transaction -> Text -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makePostingErrorExcerptByIndex :: Transaction -> Int -> Maybe (Int, Maybe Int) -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makePostingAccountErrorExcerpt :: Posting -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- makeBalanceAssertionErrorExcerpt :: Posting -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
- transactionFindPostingIndex :: (Posting -> Bool) -> Transaction -> Maybe Int
Documentation
decorateExcerpt :: Int -> Maybe (Int, Maybe Int) -> Text -> Text Source #
Decorate a data excerpt with megaparsec-style left margin, line number, and marker/underline for the column(s) if known, for inclusion in an error message.
makeAccountTagErrorExcerpt :: (AccountName, AccountDeclarationInfo) -> TagName -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
Given an account name and its account directive, and a problem tag within the latter: render it as a megaparsec-style excerpt, showing the original line number and marked column or region. Returns the file path, line number, column(s) if known, and the rendered excerpt, or as much of these as is possible. The returned columns will be accurate for the rendered error message but not for the original journal data.
makeCommodityTagErrorExcerpt :: Commodity -> TagName -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
Given a commodity and a problem tag within it: render it as a megaparsec-style excerpt, showing the original line number. Returns the file path, line number, column(s) if known, and the rendered excerpt.
makePriceDirectiveErrorExcerpt :: PriceDirective -> Maybe (PriceDirective -> Text -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
Given a problem price directive, and maybe a function to calculate the error region's column(s) (currently ignored): generate a megaparsec-style error message with highlighted excerpt. Returns the source file path, line number, column(s) if known, and the rendered excerpt, or as much of these as possible. Columns will be accurate for the rendered error message, not for the original journal entry.
makeTransactionErrorExcerpt :: Transaction -> (Transaction -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
makePostingErrorExcerpt :: Posting -> (Posting -> Transaction -> Text -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
Given a problem posting and a function calculating the best column(s) for marking the error region: look up error info from the parent transaction, and render the transaction as a megaparsec-style excerpt, showing the original line number on the problem posting's line, and a column indicator. Returns the file path, line number, column(s) if known, and the rendered excerpt, or as much of these as is possible. A limitation: columns will be accurate for the rendered error message but not for the original journal data.
makePostingErrorExcerptByIndex :: Transaction -> Int -> Maybe (Int, Maybe Int) -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
Like makePostingErrorExcerpt, but identifies the posting by its
0-based index in the transaction rather than by equality search.
This avoids false mismatches when postings have been modified after parsing
(e.g. by the balancer), and is unambiguous when duplicate postings exist.
The optional column tuple, if provided, adds a "^^^^" highlight under the posting.
makePostingAccountErrorExcerpt :: Posting -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
From the given posting, make an error excerpt showing the transaction with this posting's account part highlighted.
makeBalanceAssertionErrorExcerpt :: Posting -> (FilePath, Int, Maybe (Int, Maybe Int), Text) Source #
From the given posting, make an error excerpt showing the transaction with the balance assertion highlighted.
transactionFindPostingIndex :: (Posting -> Bool) -> Transaction -> Maybe Int Source #
Find the 1-based index of the first posting in this transaction satisfying the given predicate.