1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

config: Improve logging of errors

Currently, the config package logs errors itself, in addition to
returning them.

That is confusing and results in some duplication of logging.

This patch makes config just return errors, and adjusts the callers
to log them properly.
This commit is contained in:
Alberto Bertogli
2020-05-16 23:46:43 +01:00
parent 50986a7b7e
commit b1fe4f81f9
3 changed files with 9 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ package config
//go:generate protoc --go_out=. --go_opt=paths=source_relative config.proto
import (
"fmt"
"io/ioutil"
"os"
@@ -19,15 +20,12 @@ func Load(path string) (*Config, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
log.Errorf("Failed to read config at %q", path)
log.Errorf(" (%v)", err)
return nil, err
return nil, fmt.Errorf("failed to read config at %q: %v", path, err)
}
err = prototext.Unmarshal(buf, c)
if err != nil {
log.Errorf("Error parsing config: %v", err)
return nil, err
return nil, fmt.Errorf("parsing config: %v", err)
}
// Fill in defaults for anything that's missing.
@@ -35,8 +33,7 @@ func Load(path string) (*Config, error) {
if c.Hostname == "" {
c.Hostname, err = os.Hostname()
if err != nil {
log.Errorf("Could not get hostname: %v", err)
return nil, err
return nil, fmt.Errorf("could not get hostname: %v", err)
}
}