From b00fc45c0dee58066963d9ae4a34786ee2fd5625 Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@lyda.ie>
Date: Thu, 1 Dec 2022 15:21:17 +0000
Subject: [PATCH] Clean up error handling.

---
 bar/run.go         | 19 +------------------
 modules/modules.go |  4 +++-
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/bar/run.go b/bar/run.go
index 84a7f96..a4761ff 100644
--- a/bar/run.go
+++ b/bar/run.go
@@ -30,24 +30,7 @@ func handleCommands() {
 func Run(cmd *cobra.Command, args []string) {
 	viper.BindPFlags(cmd.Flags())
 	cfg, err := config.ReadConfig(viper.GetString("config"))
-	if err != nil {
-		// TODO Make a better default
-		cfg, err = config.ReadConfigStr(`---
-refresh: 5
-modules:
-  - module: text
-    name: post
-    params:
-      text: "post"
-      color: "#11ff11"
-    on-click: xdg-open https://mastodon.ie/
-  - module: date
-    params:
-      format: 06-05-04 15:02
-    on-click: xdg-open https://calendar.google.com/
-`)
-		cobra.CheckErr(err)
-	}
+	cobra.CheckErr(err)
 	if cfg.Refresh < 1 {
 		cfg.Refresh = 5
 	}
diff --git a/modules/modules.go b/modules/modules.go
index 216064a..ea2ff25 100644
--- a/modules/modules.go
+++ b/modules/modules.go
@@ -1,6 +1,8 @@
 package modules
 
 import (
+	"fmt"
+
 	"gopkg.in/yaml.v3"
 )
 
@@ -41,7 +43,7 @@ func (m *Module) UnmarshalYAML(node *yaml.Node) error {
 	case "text":
 		m.Params = NewText(m)
 	default:
-		panic("module unknown")
+		return fmt.Errorf("module '%s' is unknown", params.Module)
 	}
 	return params.Params.Decode(m.Params)
 }
-- 
GitLab