From 4c3baa4a949ab9dbd59ee6eafd1686373a6d3929 Mon Sep 17 00:00:00 2001 From: g3rk6 Date: Mon, 25 Jan 2016 22:56:20 -0500 Subject: [PATCH] Fixed the issue of incorrect defer and error checking order. The error checking must be first otherwise it will cause panic. --- viper.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/viper.go b/viper.go index 8625687..b9b5331 100644 --- a/viper.go +++ b/viper.go @@ -1082,11 +1082,10 @@ func (v *Viper) SaveConfig() error { } f, err := os.Create(v.getConfigFile()) - defer f.Close() - if err != nil { return err } + defer f.Close() switch v.getConfigType() { case "json":