-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy patherrors.go
More file actions
93 lines (73 loc) · 2.53 KB
/
errors.go
File metadata and controls
93 lines (73 loc) · 2.53 KB
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
package viper
import (
"fmt"
)
// FileLookupError is returned when Viper cannot resolve a configuration file.
//
// This is meant to be a common interface for all file look-up errors, occurring either because a
// file does not exist or because it cannot find any file matching finder criteria.
type FileLookupError interface {
error
fileLookup()
}
// ConfigFileNotFoundError denotes failing to find a configuration file from a search.
//
// Deprecated: This is error wraps [FileNotFoundFromSearchError], which should be used instead.
type ConfigFileNotFoundError struct {
locations []string
name string
}
// Error returns the formatted error.
func (e ConfigFileNotFoundError) Error() string {
return e.Unwrap().Error()
}
// Unwraps to FileNotFoundFromSearchError.
func (e ConfigFileNotFoundError) Unwrap() error {
return FileNotFoundFromSearchError(e)
}
// FileNotFoundFromSearchError denotes failing to find a configuration file from a search.
// Wraps ConfigFileNotFoundError.
type FileNotFoundFromSearchError struct {
locations []string
name string
}
func (e FileNotFoundFromSearchError) fileLookup() {}
// Error returns the formatted error.
func (e FileNotFoundFromSearchError) Error() string {
message := fmt.Sprintf("File %q not found", e.name)
if len(e.locations) > 0 {
message += fmt.Sprintf(" in %v", e.locations)
}
return message
}
// FileNotFoundError denotes failing to find a specific configuration file.
type FileNotFoundError struct {
err error
path string
}
func (e FileNotFoundError) fileLookup() {}
// Error returns the formatted error.
func (e FileNotFoundError) Error() string {
return fmt.Sprintf("file not found: %s", e.path)
}
// ConfigFileAlreadyExistsError denotes failure to write new configuration file.
type ConfigFileAlreadyExistsError string
// Error returns the formatted error when configuration already exists.
func (e ConfigFileAlreadyExistsError) Error() string {
return fmt.Sprintf("Config File %q Already Exists", string(e))
}
// ConfigMarshalError happens when failing to marshal the configuration.
type ConfigMarshalError struct {
err error
}
// Error returns the formatted configuration error.
func (e ConfigMarshalError) Error() string {
return fmt.Sprintf("While marshaling config: %s", e.err.Error())
}
// UnsupportedConfigError denotes encountering an unsupported
// configuration filetype.
type UnsupportedConfigError string
// Error returns the formatted configuration error.
func (str UnsupportedConfigError) Error() string {
return fmt.Sprintf("Unsupported Config Type %q", string(str))
}