Skip to content

Commit 01b5366

Browse files
authored
Fix config detection when path is invalid. (#1377)
1 parent f18077b commit 01b5366

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/util/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetOTELConfigArgs(dir string) []string {
3232
func getSortedYAMLs(dir string) []string {
3333
var configs []string
3434
_ = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
35-
if d.IsDir() {
35+
if d == nil || d.IsDir() {
3636
return nil
3737
}
3838
if filepath.Ext(path) == constants.FileSuffixYAML {

internal/util/config/config_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515
)
1616

1717
func TestGetOTELConfigArgs(t *testing.T) {
18+
got := GetOTELConfigArgs("/not/valid/path")
19+
assert.Len(t, got, 2)
20+
assert.Equal(t, []string{
21+
"-otelconfig", paths.YamlConfigPath,
22+
}, got)
23+
1824
dir := t.TempDir()
1925
// skipped
2026
require.NoError(t, os.Mkdir(filepath.Join(dir, "bunchofyaml"), 0644))
@@ -32,7 +38,7 @@ func TestGetOTELConfigArgs(t *testing.T) {
3238
require.NoError(t, err)
3339
require.NoError(t, f.Close())
3440
}
35-
got := GetOTELConfigArgs(dir)
41+
got = GetOTELConfigArgs(dir)
3642
assert.Len(t, got, 14)
3743
assert.Equal(t, []string{
3844
"-otelconfig", filepath.Join(dir, "1.yaml"),

0 commit comments

Comments
 (0)