Skip to content

Commit 34f9993

Browse files
committed
feat(cli): Rework error handling
Be more lenient in accepting statements that fail sanity checks.
1 parent 5cb56f3 commit 34f9993

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

cli/src/main/kotlin/Main.kt

+9-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package dev.schuberth.stan.cli
44

55
import com.github.ajalt.clikt.core.CliktCommand
6-
import com.github.ajalt.clikt.core.ProgramResult
76
import com.github.ajalt.clikt.core.UsageError
87
import com.github.ajalt.clikt.core.context
98
import com.github.ajalt.clikt.core.main
@@ -144,8 +143,7 @@ class Main : CliktCommand(), Logger {
144143
println("Successfully parsed ${parsedStatements.size} of ${statementFiles.size} statement(s) in $duration.\n")
145144

146145
if (parsedStatements.isEmpty()) {
147-
System.err.println("No statements found.")
148-
throw ProgramResult(2)
146+
throw UsageError("No statements found.", "statementGlobs")
149147
}
150148

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

155153
sortedStatements.zipWithNext().forEach { (curr, next) ->
156154
if (curr.bankId != next.bankId) {
157-
System.err.println(
155+
logger.error {
158156
"Statements '${curr.filename}' (${curr.bankId}) and '${next.filename}' (${next.bankId}) do not " +
159157
"belong to the same bank."
160-
)
161-
throw ProgramResult(2)
158+
}
162159
}
163160

164161
if (curr.accountId != next.accountId) {
165-
System.err.println(
162+
logger.error {
166163
"Statements '${curr.filename}' (${curr.accountId}) and '${next.filename}' (${next.accountId}) do " +
167164
"not belong to the same account."
168-
)
169-
throw ProgramResult(2)
165+
}
170166
}
171167

172168
if (curr.toDate.plusDays(1) != next.fromDate) {
173-
System.err.println(
169+
logger.error {
174170
"Statements '${curr.filename}' (${curr.toDate}) and '${next.filename}' (${next.fromDate}) are " +
175171
"not consecutive."
176-
)
177-
throw ProgramResult(2)
172+
}
178173
}
179174

180175
if (curr.balanceNew != next.balanceOld) {
181-
System.err.println(
176+
logger.error {
182177
"Balances of statements '${curr.filename}' (${curr.balanceNew}) and '${next.filename}' " +
183178
"(${next.balanceOld}) are not successive."
184-
)
185-
throw ProgramResult(2)
179+
}
186180
}
187181
}
188182

0 commit comments

Comments
 (0)