This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy patherror.go
105 lines (85 loc) · 2.63 KB
/
error.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package updater
import "fmt"
// ErrorType is a unique short string denoting the error category
type ErrorType string
const (
// UnknownError is for if we had an unknown error
UnknownError ErrorType = "unknown"
// CancelError is for if we canceled
CancelError ErrorType = "cancel"
// ConfigError is for errors reading/saving config
ConfigError ErrorType = "config"
// ConfigError is for when the GUI is active
GUIBusyError ErrorType = "guiBusy"
)
// Errors corresponding to each stage in the update process
const (
// FindError is an error trying to find the update
FindError ErrorType = "find"
// PromptError is an UI prompt error
PromptError ErrorType = "prompt"
// DownloadError is an error trying to download the update
DownloadError ErrorType = "download"
// ApplyError is an error applying the update
ApplyError ErrorType = "apply"
// VerifyError is an error verifing the update (signature or digest)
VerifyError ErrorType = "verify"
)
func (t ErrorType) String() string {
return string(t)
}
// Error is an update error with a type/category for reporting
type Error struct {
errorType ErrorType
source error
}
// NewError constructs an Error from a source error
func NewError(errorType ErrorType, err error) Error {
return Error{errorType: errorType, source: err}
}
// TypeString returns a unique short string to denote the error type
func (e Error) TypeString() string {
return e.errorType.String()
}
// IsCancel returns true if error was from a cancel
func (e Error) IsCancel() bool {
return e.errorType == CancelError
}
// IsGUIBusy returns true if the UI was active
func (e Error) IsGUIBusy() bool {
return e.errorType == GUIBusyError
}
// Error returns description for an UpdateError
func (e Error) Error() string {
if e.source == nil {
return fmt.Sprintf("Update Error (%s)", e.TypeString())
}
return fmt.Sprintf("Update Error (%s): %s", e.TypeString(), e.source.Error())
}
// CancelErr can be returned by lifecycle methods to abort an update
func CancelErr(err error) Error {
return NewError(CancelError, err)
}
func guiBusyErr(err error) Error {
return NewError(GUIBusyError, err)
}
func promptErr(err error) Error {
return NewError(PromptError, err)
}
func findErr(err error) Error {
return NewError(FindError, err)
}
func downloadErr(err error) Error {
return NewError(DownloadError, err)
}
func verifyErr(err error) Error {
return NewError(VerifyError, err)
}
func applyErr(err error) Error {
return NewError(ApplyError, err)
}
func configErr(err error) Error {
return NewError(ConfigError, err)
}