Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Skip EOF error when default empty yaml file #37445

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/config/file_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -146,7 +147,7 @@ func (fs *FileSource) loadFromFile() error {

var node yaml.Node
decoder := yaml.NewDecoder(bytes.NewReader(data))
if err := decoder.Decode(&node); err != nil {
if err := decoder.Decode(&node); err != nil && !errors.Is(err, io.EOF) {
return errors.Wrap(err, "YAML unmarshal failed: "+configFile)
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/config/file_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package config

import (
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestEmptyYaml(t *testing.T) {
file, err := os.CreateTemp(os.TempDir(), "milvus_ut_config_fs_*.yaml")
require.NoError(t, err)

filepath := file.Name()

file.WriteString("#")
file.Close()

defer os.Remove(filepath)

fs := NewFileSource(&FileInfo{
Files: []string{filepath},
RefreshInterval: time.Hour,
})

_, err = fs.GetConfigurations()
assert.NoError(t, err)

fs.Close()
}
Loading