Added descriptive strings to errors
This commit is contained in:
@@ -42,7 +42,7 @@ func get_config(config_dir string) (*Config, error) {
|
|||||||
|
|
||||||
err := os.MkdirAll(config_dir, 0755)
|
err := os.MkdirAll(config_dir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, err
|
return &config, fmt.Errorf("ERROR: Could not create config directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config_path := filepath.Join(config_dir, "server.toml")
|
config_path := filepath.Join(config_dir, "server.toml")
|
||||||
@@ -54,19 +54,19 @@ func get_config(config_dir string) (*Config, error) {
|
|||||||
defer config_file.Close()
|
defer config_file.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, err
|
return &config, fmt.Errorf("ERROR: Could not open config file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := config_file.Stat()
|
fi, err := config_file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, err
|
return &config, fmt.Errorf("ERROR: Could not get config file size: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.Size() == 0 {
|
if fi.Size() == 0 {
|
||||||
// if file is empty, write default config
|
// if file is empty, write default config
|
||||||
data, err := toml.Marshal(config)
|
data, err := toml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, err
|
return &config, fmt.Errorf("ERROR: Could not write default config to file: %v", err)
|
||||||
}
|
}
|
||||||
config_file.Write(data)
|
config_file.Write(data)
|
||||||
// return nil as the user must edit the config file
|
// return nil as the user must edit the config file
|
||||||
@@ -75,11 +75,11 @@ func get_config(config_dir string) (*Config, error) {
|
|||||||
// try to parse config file
|
// try to parse config file
|
||||||
data, err := ioutil.ReadAll(config_file)
|
data, err := ioutil.ReadAll(config_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, err
|
return &config, fmt.Errorf("ERROR: Could not read data from config file: %v", err)
|
||||||
}
|
}
|
||||||
err = toml.Unmarshal(data, &config)
|
err = toml.Unmarshal(data, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &config, err
|
return &config, fmt.Errorf("ERROR: Colud not parse config file contents: %v", err)
|
||||||
}
|
}
|
||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user