Explorar el Código

fix(util): return default config if os.UserHomeDir() returns err

rigormorrtiss hace 4 años
padre
commit
56b4f74dff
Se han modificado 1 ficheros con 5 adiciones y 5 borrados
  1. 5 5
      util/config.go

+ 5 - 5
util/config.go

@@ -17,15 +17,15 @@ type Config struct {
 
 // NewConfig reads the configuration file (if exists) and returns a new config.
 func NewConfig() *Config {
-	userHomeDir, err := os.UserHomeDir()
-	if err != nil {
-		panic(err)
-	}
-
 	c := Config{
 		Mouse:            true,
 		GetMessagesLimit: 50,
 	}
+
+	userHomeDir, err := os.UserHomeDir()
+	if err != nil {
+		return &c
+	}
 	configPath := userHomeDir + "/.config/discordo/config.json"
 	if _, err := os.Stat(configPath); os.IsNotExist(err) {
 		return &c