Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
fix: exit on config under not exists dir
Browse files Browse the repository at this point in the history
  • Loading branch information
boypt committed Aug 4, 2021
1 parent 9b6d031 commit 28fec4d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions engine/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package engine

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -84,7 +85,7 @@ func InitConf(specPath *string) (*Config, error) {

configExists := true
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
if errors.Is(err, os.ErrNotExist) {
// user set a config that is not exists, will write to it later
configExists = false
} else {
Expand All @@ -108,7 +109,9 @@ func InitConf(specPath *string) (*Config, error) {
}

if !configExists || dirChanged {
c.WriteDefault()
if err := c.WriteDefault(); err != nil {
return nil, err
}
log.Println("[config] config file updated: ", *specPath, "exists:", configExists, "dirchanged", dirChanged)
}

Expand Down

0 comments on commit 28fec4d

Please sign in to comment.