diff options
author | Alan Pearce | 2024-04-15 22:52:41 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-16 18:10:17 +0200 |
commit | 27448f33dce9141316bb4ea6d905305d8a846cac (patch) | |
tree | d39bfed3da6beac0b8a5a4c2d163c6a0f2aef1f8 /internal/config/config.go | |
parent | 0b61d3995bc01a5c8345b719459da261b92d3063 (diff) | |
download | website-27448f33dce9141316bb4ea6d905305d8a846cac.tar.lz website-27448f33dce9141316bb4ea6d905305d8a846cac.tar.zst website-27448f33dce9141316bb4ea6d905305d8a846cac.zip |
wip: verbose error handling
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index aa46e6a..12b9395 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,7 +1,10 @@ package config import ( + "io/fs" + "github.com/BurntSushi/toml" + "github.com/pkg/errors" ) type Taxonomy struct { @@ -30,8 +33,19 @@ type Config struct { Menus map[string][]MenuItem } -func GetConfig() (error, Config) { +func GetConfig() (*Config, error) { config := Config{} _, err := toml.DecodeFile("config.toml", &config) - return err, config + if err != nil { + var pathError *fs.PathError + var tomlError toml.ParseError + if errors.As(err, &pathError) { + return nil, errors.WithMessage(err, "could not read configuration") + } else if errors.As(err, &tomlError) { + return nil, errors.WithMessage(err, tomlError.ErrorWithUsage()) + } else { + return nil, errors.Wrap(err, "config error") + } + } + return &config, nil } |