about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-04-15 22:52:41 +0200
committerAlan Pearce2024-04-16 18:10:17 +0200
commit27448f33dce9141316bb4ea6d905305d8a846cac (patch)
treed39bfed3da6beac0b8a5a4c2d163c6a0f2aef1f8 /internal
parent0b61d3995bc01a5c8345b719459da261b92d3063 (diff)
downloadwebsite-27448f33dce9141316bb4ea6d905305d8a846cac.tar.lz
website-27448f33dce9141316bb4ea6d905305d8a846cac.tar.zst
website-27448f33dce9141316bb4ea6d905305d8a846cac.zip
wip: verbose error handling
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
 }