about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go18
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
 }