Skip to content

Commit bb1f2d0

Browse files
authored
fix: ignore empty config file in config validation (#561)
1 parent 3bd093c commit bb1f2d0

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pkg/config/validate.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
_ "embed"
5+
"fmt"
56
"os"
67
"strings"
78

@@ -17,19 +18,24 @@ var schemaData string
1718
func validateSchema(cfgFile string) error {
1819
// ignore if file not exists
1920
if _, err := os.Stat(cfgFile); err != nil {
21+
// Config file does not exist or is not readable - ignore it
2022
//nolint:nilerr
2123
return nil
2224
}
2325
// Load YAML file
2426
yamlContent, err := os.ReadFile(cfgFile)
2527
if err != nil {
26-
return err
28+
return fmt.Errorf("config file %q is invalid: %w", cfgFile, err)
2729
}
2830

2931
return validateYAML(yamlContent)
3032
}
3133

3234
func validateYAML(yamlContent []byte) error {
35+
if yamlContent == nil || strings.TrimSpace(string(yamlContent)) == "" {
36+
return nil
37+
}
38+
3339
// Convert YAML to JSON
3440
var yamlData any
3541
err := yaml.Unmarshal(yamlContent, &yamlData)

pkg/config/validate_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ var _ = Describe("Config", func() {
3636
err = validateYAML(data)
3737
Ω(err).ShouldNot(HaveOccurred())
3838
})
39+
It("validate config with empty file", func() {
40+
var data []byte
41+
err := validateYAML(data)
42+
Ω(err).ShouldNot(HaveOccurred())
43+
})
3944
})
4045
})

pkg/mocks/client/mock.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)