summaryrefslogtreecommitdiffstats
path: root/pkg/gui/errors.go
blob: e0f37d3ea1fdf077c2fe5c8281d8e48137b499e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 {
	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{
		ErrNoFiles:    errors.New(gui.Tr.NoChangedFiles),
		ErrSwitchRepo: errors.New("switching repo"),
		ErrRestart:    errors.New("restarting"),
	}
}

func (gui *Gui) sentinelErrorsArr() []error {
	return []error{
		gui.Errors.ErrNoFiles,
		gui.Errors.ErrSwitchRepo,
		gui.Errors.ErrRestart,
	}
}