mirror of
https://codeberg.org/scip/kleingebaeck.git
synced 2025-12-17 04:21:00 +01:00
fix error handling when trying to open files
This commit is contained in:
23
config.go
23
config.go
@@ -34,7 +34,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION string = "0.3.9"
|
VERSION string = "0.3.10"
|
||||||
Baseuri string = "https://www.kleinanzeigen.de"
|
Baseuri string = "https://www.kleinanzeigen.de"
|
||||||
Listuri string = "/s-bestandsliste.html"
|
Listuri string = "/s-bestandsliste.html"
|
||||||
Defaultdir string = "."
|
Defaultdir string = "."
|
||||||
@@ -183,13 +183,22 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
|
|
||||||
// Load the config file[s]
|
// Load the config file[s]
|
||||||
for _, cfgfile := range configfiles {
|
for _, cfgfile := range configfiles {
|
||||||
if path, err := os.Stat(cfgfile); !os.IsNotExist(err) {
|
path, err := os.Stat(cfgfile)
|
||||||
if !path.IsDir() {
|
|
||||||
if err := kloader.Load(file.Provider(cfgfile), toml.Parser()); err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error loading config file: %w", err)
|
// ignore non-existent files, but bail out on any other errors
|
||||||
}
|
if !os.IsNotExist(err) {
|
||||||
|
return nil, fmt.Errorf("failed to stat config file: %w", err)
|
||||||
}
|
}
|
||||||
} // else: we ignore the file if it doesn't exists
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !path.IsDir() {
|
||||||
|
if err := kloader.Load(file.Provider(cfgfile), toml.Parser()); err != nil {
|
||||||
|
return nil, fmt.Errorf("error loading config file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// env overrides config file
|
// env overrides config file
|
||||||
|
|||||||
4
store.go
4
store.go
@@ -149,7 +149,9 @@ func ReadImage(filename string) (*bytes.Buffer, error) {
|
|||||||
|
|
||||||
func fileExists(filename string) bool {
|
func fileExists(filename string) bool {
|
||||||
info, err := os.Stat(filename)
|
info, err := os.Stat(filename)
|
||||||
if os.IsNotExist(err) {
|
|
||||||
|
if err != nil {
|
||||||
|
// return false on any error
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user