Skip to content

Commit 638b081

Browse files
authored
Merge pull request #124 from LackOfMorals/main
Fix for issue #108
2 parents 0442b4e + 902d3ce commit 638b081

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: 'Fix for issue #108 where running aura-cli for the first time to set a config value causes a panic'
3+
time: 2025-08-13T11:34:59.820531+01:00

common/clicfg/clicfg.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Config struct {
3434

3535
func NewConfig(fs afero.Fs, version string) *Config {
3636
configPath := filepath.Join(ConfigPrefix, "neo4j", "cli")
37+
fullConfigPath := filepath.Join(configPath, "config.json")
3738

3839
Viper := viper.New()
3940

@@ -46,20 +47,20 @@ func NewConfig(fs afero.Fs, version string) *Config {
4647
bindEnvironmentVariables(Viper)
4748
setDefaultValues(Viper)
4849

49-
if err := Viper.ReadInConfig(); err != nil {
50-
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
51-
if err := fs.MkdirAll(configPath, 0755); err != nil {
52-
panic(err)
53-
}
54-
if err = Viper.SafeWriteConfig(); err != nil {
55-
panic(err)
56-
}
57-
} else {
58-
// Config file was found but another error was produced
50+
if !fileutils.FileExists(fs, fullConfigPath) {
51+
if err := fs.MkdirAll(configPath, 0755); err != nil {
52+
panic(err)
53+
}
54+
if err := Viper.SafeWriteConfig(); err != nil {
5955
panic(err)
6056
}
6157
}
6258

59+
if err := Viper.ReadInConfig(); err != nil {
60+
fmt.Println("Cannot read config file.")
61+
panic(err)
62+
}
63+
6364
credentials := credentials.NewCredentials(fs, ConfigPrefix)
6465

6566
return &Config{

0 commit comments

Comments
 (0)