Browse Source

fix a bug where your auth token couldn't be saved to a configuration file if no configuration file existed

Alan Shreve 12 years ago
parent
commit
9de09f3f1d
1 changed files with 8 additions and 7 deletions
  1. 8 7
      src/ngrok/client/config.go

+ 8 - 7
src/ngrok/client/config.go

@@ -232,15 +232,16 @@ func validateProtocol(proto, propName string) (err error) {
 }
 
 func SaveAuthToken(configPath, authtoken string) (err error) {
+	// empty configuration by default for the case that we can't read it
+	c := new(Configuration)
+
 	// read the configuration
 	oldConfigBytes, err := ioutil.ReadFile(configPath)
-	if err != nil {
-		return
-	}
-
-	c := new(Configuration)
-	if err = goyaml.Unmarshal(oldConfigBytes, c); err != nil {
-		return
+	if err == nil {
+		// unmarshal if we successfully read the configuration file
+		if err = goyaml.Unmarshal(oldConfigBytes, c); err != nil {
+			return
+		}
 	}
 
 	// no need to save, the authtoken is already the correct value