Explorar el Código

Add error handler on saveConfig

Matheus Alcantara hace 5 años
padre
commit
a689ec887f
Se han modificado 1 ficheros con 6 adiciones y 5 borrados
  1. 6 5
      config.go

+ 6 - 5
config.go

@@ -126,18 +126,19 @@ var hideMenus = false
 
 // SaveConfig writes yay config to file.
 func (config *Configuration) saveConfig() error {
-	marshalledinfo, _ := json.MarshalIndent(config, "", "\t")
+	marshalledinfo, err := json.MarshalIndent(config, "", "\t")
+	if err != nil {
+		return err
+	}
 	in, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
 	if err != nil {
 		return err
 	}
 	defer in.Close()
-	_, err = in.Write(marshalledinfo)
-	if err != nil {
+	if _, err = in.Write(marshalledinfo); err != nil {
 		return err
 	}
-	err = in.Sync()
-	return err
+	return in.Sync()
 }
 
 func defaultSettings() *Configuration {