Skip to content

Commit

Permalink
config: parsed empty config only show warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Quevedo <wally@nats.io>
  • Loading branch information
wallyqs committed Aug 14, 2023
1 parent 412dee6 commit 3a20f66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/config_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,23 @@ func TestConfigCheck(t *testing.T) {
errorLine: 5,
errorPos: 6,
},
{
name: "show warnings on empty configs without values",
config: ``,
warningErr: errors.New(`config has no values or is empty`),
errorLine: 0,
errorPos: 0,
reason: "",
},
{
name: "show warnings on empty configs without values and only comments",
config: `# Valid file but has no usable values.
`,
warningErr: errors.New(`config has no values or is empty`),
errorLine: 0,
errorPos: 0,
reason: "",
},
}

checkConfig := func(config string) error {
Expand Down Expand Up @@ -1620,6 +1637,8 @@ func TestConfigCheck(t *testing.T) {
if test.reason != "" {
msg += ": " + test.reason
}
} else if test.warningErr != nil {
msg = expectedErr.Error()
} else {
msg = test.reason
}
Expand Down
3 changes: 3 additions & 0 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ func (o *Options) ProcessConfigFile(configFile string) error {
// Collect all errors and warnings and report them all together.
errors := make([]error, 0)
warnings := make([]error, 0)
if len(m) == 0 {
warnings = append(warnings, fmt.Errorf("%s: config has no values or is empty", configFile))
}

// First check whether a system account has been defined,
// as that is a condition for other features to be enabled.
Expand Down

0 comments on commit 3a20f66

Please sign in to comment.