From 2715727d1f8fa834985b76ec43e2262cf79978bb 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 9a2ace3..4eefc53 100644 --- a/viper.go +++ b/viper.go @@ -888,11 +888,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":