Commit b1fe4f81 authored by Alberto Bertogli's avatar Alberto Bertogli

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.
parent 50986a7b
......@@ -72,7 +72,7 @@ func main() {
conf, err := config.Load(*configDir + "/chasquid.conf")
if err != nil {
log.Fatalf("Error reading config: %v", err)
log.Fatalf("Error loading config: %v", err)
}
config.LogConfig(conf)
......
......@@ -206,7 +206,7 @@ func userRemove() {
func aliasesResolve() {
conf, err := config.Load(configDir + "/chasquid.conf")
if err != nil {
Fatalf("Error reading config")
Fatalf("Error loading config: %v", err)
}
_ = os.Chdir(configDir)
......@@ -250,7 +250,7 @@ func aliasesResolve() {
func printConfig() {
conf, err := config.Load(configDir + "/chasquid.conf")
if err != nil {
Fatalf("Error reading config")
Fatalf("Error loading config: %v", err)
}
fmt.Println(prototext.Format(conf))
......@@ -262,7 +262,7 @@ func domaininfoRemove() {
conf, err := config.Load(configDir + "/chasquid.conf")
if err != nil {
Fatalf("Error reading config")
Fatalf("Error loading config: %v", err)
}
// File for the corresponding domain.
......@@ -292,7 +292,7 @@ func aliasesAdd() {
conf, err := config.Load(configDir + "/chasquid.conf")
if err != nil {
Fatalf("Error reading config")
Fatalf("Error loading config: %v", err)
}
_ = os.Chdir(configDir)
......
......@@ -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)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment