11package config
22
33import (
4+ "io"
45 "os"
56
67 "github.com/cloudflare/cloudflared/logger"
@@ -27,7 +28,7 @@ type FileManager struct {
2728 notifier Notifier
2829 configPath string
2930 logger logger.Service
30- ReadConfig func (string ) (Root , error )
31+ ReadConfig func (string , logger. Service ) (Root , error )
3132}
3233
3334// NewFileManager creates a config manager
@@ -59,15 +60,15 @@ func (m *FileManager) Start(notifier Notifier) error {
5960
6061// GetConfig reads the yaml file from the disk
6162func (m * FileManager ) GetConfig () (Root , error ) {
62- return m .ReadConfig (m .configPath )
63+ return m .ReadConfig (m .configPath , m . logger )
6364}
6465
6566// Shutdown stops the watcher
6667func (m * FileManager ) Shutdown () {
6768 m .watcher .Shutdown ()
6869}
6970
70- func readConfigFromPath (configPath string ) (Root , error ) {
71+ func readConfigFromPath (configPath string , log logger. Service ) (Root , error ) {
7172 if configPath == "" {
7273 return Root {}, errors .New ("unable to find config file" )
7374 }
@@ -80,6 +81,10 @@ func readConfigFromPath(configPath string) (Root, error) {
8081
8182 var config Root
8283 if err := yaml .NewDecoder (file ).Decode (& config ); err != nil {
84+ if err == io .EOF {
85+ log .Errorf ("Configuration file %s was empty" , configPath )
86+ return Root {}, nil
87+ }
8388 return Root {}, errors .Wrap (err , "error parsing YAML in config file at " + configPath )
8489 }
8590
0 commit comments