wip: verbose error handling
1 file changed, 16 insertions(+), 2 deletions(-)
changed files
M internal/config/config.go → 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 @@ } 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 }