ref: move journal checking/pretty errors down further, to Hledger.Data

now at Hledger.Data.JournalChecks*, Hledger.Data.Errors
This commit is contained in:
Simon Michael 2022-05-09 08:45:27 -10:00
parent 307f723b0a
commit a9779b2377
9 changed files with 38 additions and 27 deletions

View File

@ -14,7 +14,9 @@ module Hledger.Data (
module Hledger.Data.Amount, module Hledger.Data.Amount,
module Hledger.Data.Balancing, module Hledger.Data.Balancing,
module Hledger.Data.Dates, module Hledger.Data.Dates,
module Hledger.Data.Errors,
module Hledger.Data.Journal, module Hledger.Data.Journal,
module Hledger.Data.JournalChecks,
module Hledger.Data.Json, module Hledger.Data.Json,
module Hledger.Data.Ledger, module Hledger.Data.Ledger,
module Hledger.Data.Period, module Hledger.Data.Period,
@ -37,7 +39,9 @@ import Hledger.Data.AccountName
import Hledger.Data.Amount import Hledger.Data.Amount
import Hledger.Data.Balancing import Hledger.Data.Balancing
import Hledger.Data.Dates import Hledger.Data.Dates
import Hledger.Data.Errors
import Hledger.Data.Journal import Hledger.Data.Journal
import Hledger.Data.JournalChecks
import Hledger.Data.Json import Hledger.Data.Json
import Hledger.Data.Ledger import Hledger.Data.Ledger
import Hledger.Data.Period import Hledger.Data.Period

View File

@ -4,7 +4,7 @@ Helpers for making error messages.
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Hledger.Read.Error ( module Hledger.Data.Errors (
makeTransactionErrorExcerpt, makeTransactionErrorExcerpt,
makePostingErrorExcerpt, makePostingErrorExcerpt,
transactionFindPostingIndex, transactionFindPostingIndex,
@ -16,7 +16,8 @@ import Data.List (find)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Hledger.Data import Hledger.Data.Transaction (showTransaction)
import Hledger.Data.Types
import Hledger.Utils import Hledger.Utils
-- | Given a problem transaction and a function calculating the best -- | Given a problem transaction and a function calculating the best

View File

@ -7,12 +7,12 @@ others can be called only via the check command.
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NamedFieldPuns #-}
module Hledger.Read.Checks ( module Hledger.Data.JournalChecks (
journalCheckAccounts, journalCheckAccounts,
journalCheckCommodities, journalCheckCommodities,
journalCheckPayees, journalCheckPayees,
module Hledger.Read.Checks.Ordereddates, module Hledger.Data.JournalChecks.Ordereddates,
module Hledger.Read.Checks.Uniqueleafnames, module Hledger.Data.JournalChecks.Uniqueleafnames,
) )
where where
@ -24,10 +24,14 @@ import qualified Data.Text as T
import Safe (atMay) import Safe (atMay)
import Text.Printf (printf) import Text.Printf (printf)
import Hledger.Data import Hledger.Data.Errors
import Hledger.Read.Checks.Ordereddates import Hledger.Data.Journal
import Hledger.Read.Checks.Uniqueleafnames import Hledger.Data.JournalChecks.Ordereddates
import Hledger.Read.Error import Hledger.Data.JournalChecks.Uniqueleafnames
import Hledger.Data.Posting (isVirtual)
import Hledger.Data.Types
import Hledger.Data.Amount (amountIsZero, amountsRaw, missingamt)
import Hledger.Data.Transaction (transactionPayee, showTransactionLineFirstPart)
-- | Check that all the journal's postings are to accounts with -- | Check that all the journal's postings are to accounts with
-- account directives, returning an error message otherwise. -- account directives, returning an error message otherwise.

View File

@ -1,4 +1,4 @@
module Hledger.Read.Checks.Ordereddates ( module Hledger.Data.JournalChecks.Ordereddates (
journalCheckOrdereddates journalCheckOrdereddates
) )
where where
@ -8,8 +8,9 @@ import Data.List (groupBy)
import Text.Printf (printf) import Text.Printf (printf)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Hledger.Data import Hledger.Data.Errors (makeTransactionErrorExcerpt)
import Hledger.Read.Error import Hledger.Data.Transaction (transactionFile, transactionDateOrDate2)
import Hledger.Data.Types
journalCheckOrdereddates :: WhichDate -> Journal -> Either String () journalCheckOrdereddates :: WhichDate -> Journal -> Either String ()
journalCheckOrdereddates whichdate j = do journalCheckOrdereddates whichdate j = do

View File

@ -1,7 +1,7 @@
{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Hledger.Read.Checks.Uniqueleafnames ( module Hledger.Data.JournalChecks.Uniqueleafnames (
journalCheckUniqueleafnames journalCheckUniqueleafnames
) )
where where
@ -13,8 +13,11 @@ import qualified Data.Text as T
import Text.Printf (printf) import Text.Printf (printf)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Hledger.Data import Hledger.Data.AccountName (accountLeafName)
import Hledger.Read.Error import Hledger.Data.Errors (makePostingErrorExcerpt)
import Hledger.Data.Journal (journalPostings, journalAccountNamesUsed)
import Hledger.Data.Posting (isVirtual)
import Hledger.Data.Types
-- | Check that all the journal's postings are to accounts with a unique leaf name. -- | Check that all the journal's postings are to accounts with a unique leaf name.
-- Otherwise, return an error message for the first offending posting. -- Otherwise, return an error message for the first offending posting.

View File

@ -42,7 +42,6 @@ module Hledger.Read (
findReader, findReader,
splitReaderPrefix, splitReaderPrefix,
runJournalParser, runJournalParser,
module Hledger.Read.Checks,
module Hledger.Read.Common, module Hledger.Read.Common,
module Hledger.Read.InputOptions, module Hledger.Read.InputOptions,
@ -76,7 +75,6 @@ import System.IO (hPutStr, stderr)
import Hledger.Data.Dates (getCurrentDay, parsedateM, showDate) import Hledger.Data.Dates (getCurrentDay, parsedateM, showDate)
import Hledger.Data.Types import Hledger.Data.Types
import Hledger.Read.Checks
import Hledger.Read.Common import Hledger.Read.Common
import Hledger.Read.InputOptions import Hledger.Read.InputOptions
import Hledger.Read.JournalReader as JournalReader import Hledger.Read.JournalReader as JournalReader

View File

@ -148,7 +148,6 @@ import Hledger.Query (Query(..), filterQuery, parseQueryTerm, queryEndDate, quer
import Hledger.Reports.ReportOptions (ReportOpts(..), queryFromFlags, rawOptsToReportOpts) import Hledger.Reports.ReportOptions (ReportOpts(..), queryFromFlags, rawOptsToReportOpts)
import Hledger.Utils import Hledger.Utils
import Hledger.Read.InputOptions import Hledger.Read.InputOptions
import Hledger.Read.Checks (journalCheckAccounts, journalCheckCommodities)
--- ** doctest setup --- ** doctest setup
-- $setup -- $setup

View File

@ -47,8 +47,11 @@ library
Hledger.Data.Amount Hledger.Data.Amount
Hledger.Data.Balancing Hledger.Data.Balancing
Hledger.Data.Dates Hledger.Data.Dates
Hledger.Read.InputOptions Hledger.Data.Errors
Hledger.Data.Journal Hledger.Data.Journal
Hledger.Data.JournalChecks
Hledger.Data.JournalChecks.Ordereddates
Hledger.Data.JournalChecks.Uniqueleafnames
Hledger.Data.Json Hledger.Data.Json
Hledger.Data.Ledger Hledger.Data.Ledger
Hledger.Data.Period Hledger.Data.Period
@ -63,11 +66,9 @@ library
Hledger.Data.Valuation Hledger.Data.Valuation
Hledger.Query Hledger.Query
Hledger.Read Hledger.Read
Hledger.Read.Checks
Hledger.Read.Checks.Ordereddates
Hledger.Read.Checks.Uniqueleafnames
Hledger.Read.Common Hledger.Read.Common
Hledger.Read.CsvReader Hledger.Read.CsvReader
Hledger.Read.InputOptions
Hledger.Read.JournalReader Hledger.Read.JournalReader
Hledger.Read.TimedotReader Hledger.Read.TimedotReader
Hledger.Read.TimeclockReader Hledger.Read.TimeclockReader
@ -89,7 +90,6 @@ library
Hledger.Utils.Text Hledger.Utils.Text
Text.Tabular.AsciiWide Text.Tabular.AsciiWide
other-modules: other-modules:
Hledger.Read.Error
Text.Megaparsec.Custom Text.Megaparsec.Custom
Text.WideString Text.WideString
Paths_hledger_lib Paths_hledger_lib

View File

@ -100,8 +100,11 @@ library:
- Hledger.Data.Amount - Hledger.Data.Amount
- Hledger.Data.Balancing - Hledger.Data.Balancing
- Hledger.Data.Dates - Hledger.Data.Dates
- Hledger.Read.InputOptions - Hledger.Data.Errors
- Hledger.Data.Journal - Hledger.Data.Journal
- Hledger.Data.JournalChecks
- Hledger.Data.JournalChecks.Ordereddates
- Hledger.Data.JournalChecks.Uniqueleafnames
- Hledger.Data.Json - Hledger.Data.Json
- Hledger.Data.Ledger - Hledger.Data.Ledger
- Hledger.Data.Period - Hledger.Data.Period
@ -116,11 +119,9 @@ library:
- Hledger.Data.Valuation - Hledger.Data.Valuation
- Hledger.Query - Hledger.Query
- Hledger.Read - Hledger.Read
- Hledger.Read.Checks
- Hledger.Read.Checks.Ordereddates
- Hledger.Read.Checks.Uniqueleafnames
- Hledger.Read.Common - Hledger.Read.Common
- Hledger.Read.CsvReader - Hledger.Read.CsvReader
- Hledger.Read.InputOptions
- Hledger.Read.JournalReader - Hledger.Read.JournalReader
# - Hledger.Read.LedgerReader # - Hledger.Read.LedgerReader
- Hledger.Read.TimedotReader - Hledger.Read.TimedotReader