Skip to content

Commit

Permalink
fix error handling when trying to open files
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas von Dein committed Dec 13, 2024
1 parent a4be51f commit 31b27be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 16 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

const (
VERSION string = "0.3.9"
VERSION string = "0.3.10"
Baseuri string = "https://www.kleinanzeigen.de"
Listuri string = "/s-bestandsliste.html"
Defaultdir string = "."
Expand Down Expand Up @@ -183,13 +183,22 @@ func InitConfig(output io.Writer) (*Config, error) {

// Load the config file[s]
for _, cfgfile := range configfiles {
if path, err := os.Stat(cfgfile); !os.IsNotExist(err) {
if !path.IsDir() {
if err := kloader.Load(file.Provider(cfgfile), toml.Parser()); err != nil {
return nil, fmt.Errorf("error loading config file: %w", err)
}
path, err := os.Stat(cfgfile)

if err != nil {
// 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)
}

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)
}
} // else: we ignore the file if it doesn't exists
}
}

// env overrides config file
Expand Down
4 changes: 3 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func ReadImage(filename string) (*bytes.Buffer, error) {

func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {

if err != nil {
// return false on any error
return false
}

Expand Down

0 comments on commit 31b27be

Please sign in to comment.