Verified Commit 6b278824 authored by 35V LG84's avatar 35V LG84

cli: enhance error messages

Provide better error message in case that configuration
file doesn't have valid content.
Signed-off-by: 35V LG84's avatar35V LG84 <35vlg84-x4e6b92@e257.fi>
parent e85c1765
Pipeline #60819733 passed with stage
in 6 minutes and 10 seconds
......@@ -217,7 +217,7 @@ object TacklerCli {
new OutputStreamWriter(Console.err, StandardCharsets.UTF_8))
con.write(msg)
con.write("\n")
con.write("\n\n")
con.flush()
con.write("Error while running Tackler, see above for reason.\n")
con.flush()
......@@ -241,26 +241,39 @@ object TacklerCli {
// Error message is already printed by CliArgs
FAILURE
case ex: ConfigurationException =>
val msg = "" +
"Error: \n" +
" Invalid tackler configuration\n" +
" message: " + ex.getMessage
reportFailure(msg)
case ex: NoSuchFileException =>
val msg="Error: File not found: " + ex.getMessage
val msg = "" +
"Error: \n" +
" File not found\n" +
" message: " + ex.getMessage
reportFailure(msg)
case ex: java.util.regex.PatternSyntaxException =>
val msg = "Error: regexp syntax error: " + ex.getMessage
val msg = "" +
"Error: \n" +
" Syntax error with regular expression\n" +
" message: " + ex.getMessage
reportFailure(msg)
case ex: TacklerParseException =>
val msg = "" +
"Exception: \n" +
" class: " + ex.getClass.toString + "\n" +
" msg: " + ex.getMessage + "\n"
" message: " + ex.getMessage
reportFailure(msg)
case ex: TacklerException =>
val msg = "" +
"Exception: \n" +
" class: " + ex.getClass.toString + "\n" +
" msg: " + ex.getMessage + "\n"
" message: " + ex.getMessage
reportFailure(msg)
}
}
......
......@@ -20,7 +20,7 @@ import java.nio.file.{Files, NoSuchFileException, Path, Paths}
import java.util.regex.PatternSyntaxException
import better.files._
import fi.e257.tackler.core.{AccountException, CommodityException, GroupByException, ReportException, TacklerException, TxnException}
import fi.e257.tackler.core.{AccountException, CommodityException, ConfigurationException, GroupByException, ReportException, TacklerException, TxnException}
import fi.e257.tackler.parser.TacklerParseException
import fi.e257.testing.{DirSuiteLike, Glob}
import org.rogach.scallop.exceptions.{ExcessArguments, RequiredOptionNotFound, UnknownOption, ValidationFailure}
......@@ -89,6 +89,13 @@ class DirsuiteAllExceptionsTest extends DirSuiteLike {
class DirsuiteExceptionsTest extends DirSuiteLike {
val basedir = Paths.get("tests")
runDirSuiteTestCases(basedir, Glob("cli/ex/ConfigurationException-*.exec")) { args: Array[String] =>
assertThrows[ConfigurationException] {
TacklerCli.runExceptions(args)
}
}
runDirSuiteTestCases(basedir, Glob("cli/ex/NoSuchFileException-*.exec")) { args: Array[String] =>
assertThrows[NoSuchFileException] {
TacklerCli.runExceptions(args)
......
......@@ -149,7 +149,17 @@ object Settings {
def apply(cfgPath: Path, initialConfig: Config): Settings = {
File(cfgPath).verifiedExists(File.LinkOptions.follow) match {
case Some(true) => new Settings(Some(cfgPath), initialConfig)
case Some(true) => {
try {
new Settings(Some(cfgPath), initialConfig)
} catch {
case ex: com.typesafe.config.ConfigException => {
val msg = "CFG: error: " + ex.getMessage
log.error(msg)
throw new ConfigurationException(msg)
}
}
}
case _ => {
log.error("CFG: Configuration file is not found or it is not readable: [" + cfgPath.toString + "]")
log.warn("CFG: Settings will NOT use configuration file, only provided and embedded configuration will be used")
......@@ -177,7 +187,7 @@ class Settings(optPath: Option[Path], providedConfig: Config) {
val cfg: Config = optPath match {
case Some(path) => {
log.info("CFG: Loading configuration by file {}", path.toString)
log.info("CFG: using file: {}", path.toString)
providedConfig
.withFallback(ConfigFactory.parseFile(path.toFile).getConfig(cfgBasename))
......
# format: exec
# test:uuid: c096f7a8-a87c-4b3c-ad37-b860775597a0
# desc: existing, but empty configuration
exec:--cfg;tests/cli/ex/empty.conf;
# Empty and hence invalid configuration file
......@@ -5,7 +5,9 @@ features:
- feature:
id: ed1537a5-494c-4a86-b65c-d2a010297d17
parent: 6278f9b8-3f98-4926-aa21-d660e03a34e0
parents:
- parent: 6278f9b8-3f98-4926-aa21-d660e03a34e0
- parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "configuration settings for audit hash function"
tests:
errors:
......@@ -63,7 +65,7 @@ features:
id: 0e76295f-aee6-47bc-ae6f-7fba5ce6d818
name: TxnDataTest
descriptions:
- desc: "Uppercase txn UUIDs resul same txn set checksum as lowercase"
- desc: "Uppercase txn UUIDs result same txn set checksum as lowercase"
- desc: "reports correct checksum after multiple filtering steps"
- test:
......
......@@ -11,6 +11,12 @@ mapping:
mapping:
id: { type: str }
parent: { type: str }
parents:
type: seq
sequence:
- type: map
mapping:
parent: { type: str }
subject: { type: str }
tests:
type: map
......
......@@ -154,9 +154,23 @@ features:
references:
- ref: identity
###
### Configuration settings
###
- feature:
id: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "Setup by configuration"
tests:
errors:
- error:
id: c096f7a8-a87c-4b3c-ad37-b860775597a0
name: cli/ex/ConfigurationException-empty-conf.exec
desc: "Existing cfg-file, empty content"
### conf: timezone
- feature:
id: b01b4c9b-ebb9-4e38-b910-fb932374057c
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: timezone"
tests:
operations:
......@@ -178,6 +192,7 @@ features:
### conf: basedir
- feature:
id: 4d7f9feb-2d2f-4c50-b195-60b024bc9999
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: basedir"
tests:
operations:
......@@ -187,6 +202,7 @@ features:
### conf: input.txn
- feature:
id: b3f82d40-1e18-4457-8050-61759a0c0cac
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: input.fs.dir"
tests:
errors:
......@@ -200,6 +216,7 @@ features:
- feature:
id: cf543686-e36f-4f5f-91ed-06498e37c4bb
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: input.fs.glob"
tests:
operations:
......@@ -209,6 +226,7 @@ features:
### conf: reporting.
- feature:
id: 048dca18-eba8-4875-baa5-524ff8c8f903
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reporting.reports"
tests:
operations:
......@@ -219,6 +237,7 @@ features:
- feature:
id: 57cd42b2-7319-42dd-a0be-809927f66bdd
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reporting.formats"
tests:
operations:
......@@ -235,6 +254,7 @@ features:
- feature:
id: 4f83e4ad-4bc9-46a1-9f1e-b4863e8a2839
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reporting.accounts"
tests:
operations:
......@@ -251,6 +271,7 @@ features:
- feature:
id: ebc16b71-b5df-46f7-bba6-e0d9ac37d6ee
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reporting.console"
tests:
operations:
......@@ -273,6 +294,7 @@ features:
### conf: reports.balance
- feature:
id: 9f348a4c-7d6d-4c64-8f67-da34b63b916a
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.balance.title"
tests:
operations:
......@@ -281,6 +303,7 @@ features:
- feature:
id: 8aa7e91d-b738-44af-af72-4ef160e1f87f
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.balance.accounts"
tests:
operations:
......@@ -290,6 +313,7 @@ features:
### conf reports.balance-group
- feature:
id: c7e846f8-ba22-47be-9e02-c76badc42a65
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.balance-group.title"
tests:
operations:
......@@ -298,6 +322,7 @@ features:
- feature:
id: 33ba3703-7232-4974-8e5d-23b567413bcd
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.balance-group.accounts"
tests:
operations:
......@@ -306,6 +331,7 @@ features:
- feature:
id: 1957610a-5ea2-4582-8114-e6fe87986adf
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.balance-group.group-by"
tests:
errors:
......@@ -326,6 +352,7 @@ features:
### conf: reports.register
- feature:
id: 11eaf2b4-b55c-4bb0-bd63-8de82aed62a9
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.register.title"
tests:
operations:
......@@ -334,6 +361,7 @@ features:
- feature:
id: a65cc023-93e3-4b19-a9aa-9a35f590bea7
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: reports.register.accounts"
tests:
operations:
......@@ -343,6 +371,7 @@ features:
### conf: accounts
- feature:
id: acfee245-078c-45c6-8a87-e3d47598a3ef
parent: 75b0fc6d-0af7-4244-b8df-e99019678818
subject: "conf: accounts.strict"
tests:
operations:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment