Skip to content

Commit

Permalink
feat(cli): Rework error handling
Browse files Browse the repository at this point in the history
Be more lenient in accepting statements that fail sanity checks.
  • Loading branch information
sschuberth committed Sep 16, 2024
1 parent 5cb56f3 commit 7f0ab6a
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions cli/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class Main : CliktCommand(), Logger {
println("Successfully parsed ${parsedStatements.size} of ${statementFiles.size} statement(s) in $duration.\n")

if (parsedStatements.isEmpty()) {
System.err.println("No statements found.")
throw ProgramResult(2)
System.err.println()
throw UsageError("No statements found.", "statementGlobs")
}

println("Checking parsed statements for consistency...")
Expand All @@ -154,35 +154,31 @@ class Main : CliktCommand(), Logger {

sortedStatements.zipWithNext().forEach { (curr, next) ->
if (curr.bankId != next.bankId) {
System.err.println(
logger.error {
"Statements '${curr.filename}' (${curr.bankId}) and '${next.filename}' (${next.bankId}) do not " +
"belong to the same bank."
)
throw ProgramResult(2)
}
}

if (curr.accountId != next.accountId) {
System.err.println(
logger.error {
"Statements '${curr.filename}' (${curr.accountId}) and '${next.filename}' (${next.accountId}) do " +
"not belong to the same account."
)
throw ProgramResult(2)
}
}

if (curr.toDate.plusDays(1) != next.fromDate) {
System.err.println(
logger.error {
"Statements '${curr.filename}' (${curr.toDate}) and '${next.filename}' (${next.fromDate}) are " +
"not consecutive."
)
throw ProgramResult(2)
}
}

if (curr.balanceNew != next.balanceOld) {
System.err.println(
logger.error {
"Balances of statements '${curr.filename}' (${curr.balanceNew}) and '${next.filename}' " +
"(${next.balanceOld}) are not successive."
)
throw ProgramResult(2)
}
}
}

Expand Down

0 comments on commit 7f0ab6a

Please sign in to comment.