From dc02ae94afd4082d86741386e75e59cbea47aa56 Mon Sep 17 00:00:00 2001 From: Alex Rawson Date: Sat, 1 Oct 2022 17:34:48 -0500 Subject: [PATCH] Add warnings for possible mistakes (#152) I definitely haven't spent any time at all being confused by these or anything like that. 0 time whatsoever. Anyway, if someone else makes a mistake like this, the new warnings could serve as a hint that something is wrong. --- configs.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/configs.go b/configs.go index cc43b512..6759f97c 100644 --- a/configs.go +++ b/configs.go @@ -17,11 +17,16 @@ func parseConfig(configContent string) { fail("Configuration is empty!") os.Exit(1) } - - if _, err := toml.Decode(configContent, &conf); err != nil { + md, err := toml.Decode(configContent, &conf) + if err != nil { fail("Error decoding TOML: " + err.Error()) os.Exit(1) } + if verboseEnabled { + for _, undecoded := range md.Undecoded() { + warn("Undecoded scoring key \"" + undecoded.String() + "\" will not be used") + } + } // If there's no remote, local must be enabled. if conf.Remote == "" { @@ -45,6 +50,18 @@ func parseConfig(configContent string) { info("Consider updating your config to include:") info(" version = '" + version + "'") } + + for i, check := range conf.Check { + allConditions := append(append(append([]cond{}, check.Pass[:]...), check.Fail[:]...), check.PassOverride[:]...) + if len(allConditions) == 0 { + warn("Check " + fmt.Sprintf("%d", i+1) + " does not define any possible ways to pass") + } + for j, cond := range allConditions { + if cond.Type == "" { + warn("Check " + fmt.Sprintf("%d condition %d", i+1, j+1) + " has an empty type and will crash at runtime") + } + } + } } // writeConfig writes the in-memory config to disk as the an encrypted