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

Related to #37404

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-11-05 19:26:24 +08:00 committed by GitHub
parent 9a9de3df5c
commit 0645d46ec6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package config
import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"sync"
@ -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)
}

View File

@ -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()
}