summaryrefslogtreecommitdiffstats
path: root/pkg/gui/errors.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-03-31 23:55:06 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-04-02 11:00:15 +1100
commit7d62f103e4a1b39b7e8fbd0e1f39815c525cd588 (patch)
tree83e331beeee07d066c76580e044234f18063a0a7 /pkg/gui/errors.go
parent9e85d37fb949bbc83f28cb079f2ac4b45ae895ce (diff)
big refactor to give our enums actual types
Diffstat (limited to 'pkg/gui/errors.go')
-rw-r--r--pkg/gui/errors.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/pkg/gui/errors.go b/pkg/gui/errors.go
new file mode 100644
index 000000000..d8aa7530d
--- /dev/null
+++ b/pkg/gui/errors.go
@@ -0,0 +1,42 @@
+package gui
+
+import "github.com/go-errors/errors"
+
+// SentinelErrors are the errors that have special meaning and need to be checked
+// by calling functions. The less of these, the better
+type SentinelErrors struct {
+ ErrSubProcess error
+ ErrNoFiles error
+ ErrSwitchRepo error
+ ErrRestart error
+}
+
+const UNKNOWN_VIEW_ERROR_MSG = "unknown view"
+
+// GenerateSentinelErrors makes the sentinel errors for the gui. We're defining it here
+// because we can't do package-scoped errors with localization, and also because
+// it seems like package-scoped variables are bad in general
+// https://dave.cheney.net/2017/06/11/go-without-package-scoped-variables
+// In the future it would be good to implement some of the recommendations of
+// that article. For now, if we don't need an error to be a sentinel, we will just
+// define it inline. This has implications for error messages that pop up everywhere
+// in that we'll be duplicating the default values. We may need to look at
+// having a default localisation bundle defined, and just using keys-only when
+// localising things in the code.
+func (gui *Gui) GenerateSentinelErrors() {
+ gui.Errors = SentinelErrors{
+ ErrSubProcess: errors.New(gui.Tr.RunningSubprocess),
+ ErrNoFiles: errors.New(gui.Tr.NoChangedFiles),
+ ErrSwitchRepo: errors.New("switching repo"),
+ ErrRestart: errors.New("restarting"),
+ }
+}
+
+func (gui *Gui) sentinelErrorsArr() []error {
+ return []error{
+ gui.Errors.ErrSubProcess,
+ gui.Errors.ErrNoFiles,
+ gui.Errors.ErrSwitchRepo,
+ gui.Errors.ErrRestart,
+ }
+}