Skip to content

Commit

Permalink
Log errors when executing balance command
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Jun 9, 2024
1 parent 8e4e8eb commit 6cefce9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
9 changes: 9 additions & 0 deletions examples/journal-broken-transaction.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file on its own is not valid,
# but it can be merged with other journals
transactions:
- utc: '2024-05-28 14:35'
note: Bread and butter
transfers:
- from: john:giro
to: non_existant_bakery
amount: 4.19 €
6 changes: 6 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ test-cli: | node_modules
balance examples/journal.yaml examples/journal-only-transactions.yaml \
> /dev/null

# Following command should fail
@bun x spago run -- \
balance examples/journal.yaml examples/journal-broken-transaction.yaml \
&& echo "❌ This must fail" && exit 1 \
|| echo "✅ Balance printed an error"

bun x spago run -- \
unused-files examples/receipts examples/journal.yaml \
2> /dev/null
Expand Down
14 changes: 1 addition & 13 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,6 @@ buildLedgerAndRun currentDir journalPathRel extraJournalPaths callback = do
Error msg -> pure $ Error msg
Ok ledger -> ledger # callback

buildRunExit
:: String
-> String
-> Array CliArgPrim
-> (Ledger -> Effect (Result String Unit))
-> Effect (Result String Unit)
buildRunExit currentDir journalPathRel extraJournalPaths callback = do
buildLedgerAndRun currentDir journalPathRel extraJournalPaths callback
>>= \res -> case res of
Ok val -> pure $ Ok val
Error msg -> errorAndExit config msg

getAllFiles :: String -> Effect (Array String)
getAllFiles directoryPath =
let
Expand Down Expand Up @@ -247,7 +235,7 @@ checkUnusedFiles
:: String -> String -> Array CliArgPrim -> Effect (Result String Unit)
checkUnusedFiles filesDirPath jourPathRel extraJournalPaths = do
currentDir <- cwd
buildRunExit currentDir jourPathRel extraJournalPaths $
buildLedgerAndRun currentDir jourPathRel extraJournalPaths $
\ledger@(Ledger { transactions }) -> do
let
journalDir =
Expand Down
9 changes: 8 additions & 1 deletion src/Oclis/Executor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,14 @@ callCliAppWithOutput doesPrint executor =
setExitCode 1
Ok cliSpec -> do
arguments <- argv
_ <- callCliAppWith cliSpec executor doesPrint arguments
result <- callCliAppWith cliSpec executor doesPrint arguments
case result of
Error errMsg -> do
error (makeRed errMsg)
setExitCode 1
Ok val -> do
log val
setExitCode 0
pure unit

callCliAppWith
Expand Down

0 comments on commit 6cefce9

Please sign in to comment.