Skip to content

Commit

Permalink
Add warnings for possible mistakes (#152)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zombiepigdragon authored Oct 1, 2022
1 parent 93d055e commit dc02ae9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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
Expand Down

0 comments on commit dc02ae9

Please sign in to comment.