From a9779b2377c07d303e867d6c2d264e8bf4a5883b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 9 May 2022 08:45:27 -1000 Subject: [PATCH] ref: move journal checking/pretty errors down further, to Hledger.Data now at Hledger.Data.JournalChecks*, Hledger.Data.Errors --- hledger-lib/Hledger/Data.hs | 4 ++++ .../Hledger/{Read/Error.hs => Data/Errors.hs} | 5 +++-- .../{Read/Checks.hs => Data/JournalChecks.hs} | 18 +++++++++++------- .../JournalChecks}/Ordereddates.hs | 7 ++++--- .../JournalChecks}/Uniqueleafnames.hs | 9 ++++++--- hledger-lib/Hledger/Read.hs | 2 -- hledger-lib/Hledger/Read/Common.hs | 1 - hledger-lib/hledger-lib.cabal | 10 +++++----- hledger-lib/package.yaml | 9 +++++---- 9 files changed, 38 insertions(+), 27 deletions(-) rename hledger-lib/Hledger/{Read/Error.hs => Data/Errors.hs} (97%) rename hledger-lib/Hledger/{Read/Checks.hs => Data/JournalChecks.hs} (91%) rename hledger-lib/Hledger/{Read/Checks => Data/JournalChecks}/Ordereddates.hs (90%) rename hledger-lib/Hledger/{Read/Checks => Data/JournalChecks}/Uniqueleafnames.hs (89%) diff --git a/hledger-lib/Hledger/Data.hs b/hledger-lib/Hledger/Data.hs index 32d3cdd55..834562fdd 100644 --- a/hledger-lib/Hledger/Data.hs +++ b/hledger-lib/Hledger/Data.hs @@ -14,7 +14,9 @@ module Hledger.Data ( module Hledger.Data.Amount, module Hledger.Data.Balancing, module Hledger.Data.Dates, + module Hledger.Data.Errors, module Hledger.Data.Journal, + module Hledger.Data.JournalChecks, module Hledger.Data.Json, module Hledger.Data.Ledger, module Hledger.Data.Period, @@ -37,7 +39,9 @@ import Hledger.Data.AccountName import Hledger.Data.Amount import Hledger.Data.Balancing import Hledger.Data.Dates +import Hledger.Data.Errors import Hledger.Data.Journal +import Hledger.Data.JournalChecks import Hledger.Data.Json import Hledger.Data.Ledger import Hledger.Data.Period diff --git a/hledger-lib/Hledger/Read/Error.hs b/hledger-lib/Hledger/Data/Errors.hs similarity index 97% rename from hledger-lib/Hledger/Read/Error.hs rename to hledger-lib/Hledger/Data/Errors.hs index 286bd187b..eb871e6f9 100644 --- a/hledger-lib/Hledger/Read/Error.hs +++ b/hledger-lib/Hledger/Data/Errors.hs @@ -4,7 +4,7 @@ Helpers for making error messages. {-# LANGUAGE OverloadedStrings #-} -module Hledger.Read.Error ( +module Hledger.Data.Errors ( makeTransactionErrorExcerpt, makePostingErrorExcerpt, transactionFindPostingIndex, @@ -16,7 +16,8 @@ import Data.List (find) import Data.Text (Text) import qualified Data.Text as T -import Hledger.Data +import Hledger.Data.Transaction (showTransaction) +import Hledger.Data.Types import Hledger.Utils -- | Given a problem transaction and a function calculating the best diff --git a/hledger-lib/Hledger/Read/Checks.hs b/hledger-lib/Hledger/Data/JournalChecks.hs similarity index 91% rename from hledger-lib/Hledger/Read/Checks.hs rename to hledger-lib/Hledger/Data/JournalChecks.hs index 7cd2c123d..7f2d0d918 100644 --- a/hledger-lib/Hledger/Read/Checks.hs +++ b/hledger-lib/Hledger/Data/JournalChecks.hs @@ -7,12 +7,12 @@ others can be called only via the check command. {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE NamedFieldPuns #-} -module Hledger.Read.Checks ( +module Hledger.Data.JournalChecks ( journalCheckAccounts, journalCheckCommodities, journalCheckPayees, - module Hledger.Read.Checks.Ordereddates, - module Hledger.Read.Checks.Uniqueleafnames, + module Hledger.Data.JournalChecks.Ordereddates, + module Hledger.Data.JournalChecks.Uniqueleafnames, ) where @@ -24,10 +24,14 @@ import qualified Data.Text as T import Safe (atMay) import Text.Printf (printf) -import Hledger.Data -import Hledger.Read.Checks.Ordereddates -import Hledger.Read.Checks.Uniqueleafnames -import Hledger.Read.Error +import Hledger.Data.Errors +import Hledger.Data.Journal +import Hledger.Data.JournalChecks.Ordereddates +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 -- account directives, returning an error message otherwise. diff --git a/hledger-lib/Hledger/Read/Checks/Ordereddates.hs b/hledger-lib/Hledger/Data/JournalChecks/Ordereddates.hs similarity index 90% rename from hledger-lib/Hledger/Read/Checks/Ordereddates.hs rename to hledger-lib/Hledger/Data/JournalChecks/Ordereddates.hs index 96d918d75..08da33954 100755 --- a/hledger-lib/Hledger/Read/Checks/Ordereddates.hs +++ b/hledger-lib/Hledger/Data/JournalChecks/Ordereddates.hs @@ -1,4 +1,4 @@ -module Hledger.Read.Checks.Ordereddates ( +module Hledger.Data.JournalChecks.Ordereddates ( journalCheckOrdereddates ) where @@ -8,8 +8,9 @@ import Data.List (groupBy) import Text.Printf (printf) import Data.Maybe (fromMaybe) -import Hledger.Data -import Hledger.Read.Error +import Hledger.Data.Errors (makeTransactionErrorExcerpt) +import Hledger.Data.Transaction (transactionFile, transactionDateOrDate2) +import Hledger.Data.Types journalCheckOrdereddates :: WhichDate -> Journal -> Either String () journalCheckOrdereddates whichdate j = do diff --git a/hledger-lib/Hledger/Read/Checks/Uniqueleafnames.hs b/hledger-lib/Hledger/Data/JournalChecks/Uniqueleafnames.hs similarity index 89% rename from hledger-lib/Hledger/Read/Checks/Uniqueleafnames.hs rename to hledger-lib/Hledger/Data/JournalChecks/Uniqueleafnames.hs index e08ba2c41..545349654 100755 --- a/hledger-lib/Hledger/Read/Checks/Uniqueleafnames.hs +++ b/hledger-lib/Hledger/Data/JournalChecks/Uniqueleafnames.hs @@ -1,7 +1,7 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} -module Hledger.Read.Checks.Uniqueleafnames ( +module Hledger.Data.JournalChecks.Uniqueleafnames ( journalCheckUniqueleafnames ) where @@ -13,8 +13,11 @@ import qualified Data.Text as T import Text.Printf (printf) import Data.Maybe (fromMaybe) -import Hledger.Data -import Hledger.Read.Error +import Hledger.Data.AccountName (accountLeafName) +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. -- Otherwise, return an error message for the first offending posting. diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index f6d189e96..9eef0a74b 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -42,7 +42,6 @@ module Hledger.Read ( findReader, splitReaderPrefix, runJournalParser, - module Hledger.Read.Checks, module Hledger.Read.Common, module Hledger.Read.InputOptions, @@ -76,7 +75,6 @@ import System.IO (hPutStr, stderr) import Hledger.Data.Dates (getCurrentDay, parsedateM, showDate) import Hledger.Data.Types -import Hledger.Read.Checks import Hledger.Read.Common import Hledger.Read.InputOptions import Hledger.Read.JournalReader as JournalReader diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index f14fdb3a1..fdc1129df 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -148,7 +148,6 @@ import Hledger.Query (Query(..), filterQuery, parseQueryTerm, queryEndDate, quer import Hledger.Reports.ReportOptions (ReportOpts(..), queryFromFlags, rawOptsToReportOpts) import Hledger.Utils import Hledger.Read.InputOptions -import Hledger.Read.Checks (journalCheckAccounts, journalCheckCommodities) --- ** doctest setup -- $setup diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 8abdda333..877be1522 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -47,8 +47,11 @@ library Hledger.Data.Amount Hledger.Data.Balancing Hledger.Data.Dates - Hledger.Read.InputOptions + Hledger.Data.Errors Hledger.Data.Journal + Hledger.Data.JournalChecks + Hledger.Data.JournalChecks.Ordereddates + Hledger.Data.JournalChecks.Uniqueleafnames Hledger.Data.Json Hledger.Data.Ledger Hledger.Data.Period @@ -63,11 +66,9 @@ library Hledger.Data.Valuation Hledger.Query Hledger.Read - Hledger.Read.Checks - Hledger.Read.Checks.Ordereddates - Hledger.Read.Checks.Uniqueleafnames Hledger.Read.Common Hledger.Read.CsvReader + Hledger.Read.InputOptions Hledger.Read.JournalReader Hledger.Read.TimedotReader Hledger.Read.TimeclockReader @@ -89,7 +90,6 @@ library Hledger.Utils.Text Text.Tabular.AsciiWide other-modules: - Hledger.Read.Error Text.Megaparsec.Custom Text.WideString Paths_hledger_lib diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index dedc88d57..756cdbc70 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -100,8 +100,11 @@ library: - Hledger.Data.Amount - Hledger.Data.Balancing - Hledger.Data.Dates - - Hledger.Read.InputOptions + - Hledger.Data.Errors - Hledger.Data.Journal + - Hledger.Data.JournalChecks + - Hledger.Data.JournalChecks.Ordereddates + - Hledger.Data.JournalChecks.Uniqueleafnames - Hledger.Data.Json - Hledger.Data.Ledger - Hledger.Data.Period @@ -116,11 +119,9 @@ library: - Hledger.Data.Valuation - Hledger.Query - Hledger.Read - - Hledger.Read.Checks - - Hledger.Read.Checks.Ordereddates - - Hledger.Read.Checks.Uniqueleafnames - Hledger.Read.Common - Hledger.Read.CsvReader + - Hledger.Read.InputOptions - Hledger.Read.JournalReader # - Hledger.Read.LedgerReader - Hledger.Read.TimedotReader