From 827e41c50ce54adf8c0bdc5e0b1983cf7cedc8e2 Mon Sep 17 00:00:00 2001 From: Suraj Narwade Date: Fri, 14 Sep 2018 21:39:35 +0530 Subject: [PATCH] Handle error in root.go --- cmd/root.go | 2 +- pkg/config/config.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index bb417e69143..53f84acdbf1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -104,7 +104,7 @@ func Execute() { // before proceeding with fetching the latest version cfg, err := config.New() if err != nil { - fmt.Println("unable to fetch configuration from Odo config file.") + checkError(err, "") } if cfg.GetUpdateNotification() == true { updateInfo := make(chan string) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5d0f145b65e..2fb1a7ee411 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -77,7 +77,15 @@ func New() (*ConfigInfo, error) { if err != nil { return nil, errors.Wrap(err, "unable to get odo config file") } - + // Check whether directory present or not + _, err = os.Stat(filepath.Dir(configFile)) + if os.IsNotExist(err) { + err = os.MkdirAll(filepath.Dir(configFile), 0755) + if err != nil { + return nil, errors.Wrap(err, "unable to create directory") + } + } + // Check whether config file is present or not _, err = os.Stat(configFile) if os.IsNotExist(err) { file, err := os.Create(configFile)