fix(config/parser.go): correct unlocking on error paths (#146)

Spotted while reading the code.
This commit is contained in:
Simone Basso 2020-07-24 17:12:51 +02:00 committed by GitHub
parent fc58c4dc45
commit 1983672e3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,6 +69,7 @@ type Config struct {
// Write the config file in json to the path
func (c *Config) Write() error {
c.Lock()
defer c.Unlock()
configJSON, _ := json.MarshalIndent(c, "", " ")
if c.path == "" {
return errors.New("config file path is empty")
@ -76,7 +77,6 @@ func (c *Config) Write() error {
if err := ioutil.WriteFile(c.path, configJSON, 0644); err != nil {
return errors.Wrap(err, "writing config JSON")
}
c.Unlock()
return nil
}