From 496f0015ba9c576d2f0c2d1386b9cb24e9860738 Mon Sep 17 00:00:00 2001 From: Shalom Yiblet Date: Mon, 12 Feb 2024 17:30:40 -0800 Subject: [PATCH] feat: ensure read config can handle when the file doesn't exist --- config.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 638441b..87d4cdc 100644 --- a/config.go +++ b/config.go @@ -61,7 +61,8 @@ func ReadConfig() (config, error) { // A common use case is to get a private config folder for your app to // place its settings files into, that are specific to the local user. configPath := configdir.LocalConfig("hlp") - err := configdir.MakePath(configPath) // Ensure it exists. + + err := os.MkdirAll(configPath, 0755) // Ensure it exists. if err != nil { return config{}, fmt.Errorf("cannot read path: %w", err) } @@ -69,6 +70,9 @@ func ReadConfig() (config, error) { // Deal with a JSON configuration file in that folder. configFile := filepath.Join(configPath, "configuration.json") if _, err = os.Stat(configFile); err != nil { + if os.IsNotExist(err) { + return config{}, nil + } return config{}, err }