This repository was archived by the owner on May 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
167 lines (134 loc) · 5.29 KB
/
Copy patherror.go
File metadata and controls
167 lines (134 loc) · 5.29 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package envconfig
import (
"errors"
"fmt"
)
// FileTypeValidationError occurs when the .env config file fails to open.
type FileTypeValidationError struct {
Filepath string
}
// Error satisfies the error interface for FileTypeValidationError.
func (e *FileTypeValidationError) Error() string {
return fmt.Sprintf("file extension is not a valid environment file: %q", e.Filepath)
}
// OpenFileError occurs when the .env config file fails to open.
type OpenFileError struct {
Err error
}
// Error satisfies the error interface for OpenFileError.
func (e *OpenFileError) Error() string {
return fmt.Sprintf("failed to open config file: %v", e.Err)
}
// Unwrap allows OpenFileError to be used with errors.Is and errors.As.
func (e *OpenFileError) Unwrap() error { return e.Err }
// SetEnvironmentVariableError occurs when the value is failed to be set in the environment.
type SetEnvironmentVariableError struct {
Err error
}
// Error satisfies the error interface for SetEnvironmentVariableError.
func (e *SetEnvironmentVariableError) Error() string {
return fmt.Sprintf("failed to set environment variable: %v", e.Err.Error())
}
// Unwrap allows SetEnvironmentVariableError to be used with errors.Is and errors.As.
func (e *SetEnvironmentVariableError) Unwrap() error { return e.Err }
// FieldConversionError occurs when a field on the config struct fails to be set.
type FieldConversionError struct {
FieldName string
TargetType string
Err error
}
// Error satisfies the error interface for FieldConversionError.
func (e *FieldConversionError) Error() string {
return fmt.Sprintf("failed to convert field %v to %v: %v", e.FieldName, e.TargetType, e.Err.Error())
}
// Unwrap allows FieldConversionError to be used with errors.Is and errors.As.
func (e *FieldConversionError) Unwrap() error { return e.Err }
// UnsupportedFieldTypeError occurs when the a field type on the config struct is not compatible.
type UnsupportedFieldTypeError struct {
FieldType any
}
// Error satisfies the error interface for UnsupportedFieldTypeError.
func (e *UnsupportedFieldTypeError) Error() string {
return fmt.Sprintf("unsupported field type: %T", e.FieldType)
}
// InvalidConfigTypeError occurs when config is not a pointer to a struct.
type InvalidConfigTypeError struct {
ProvidedType any
}
// Error satisfies the error interface for InvalidConfigTypeError.
func (e *InvalidConfigTypeError) Error() string {
return fmt.Sprintf("output must be a pointer to a struct, got %T", e.ProvidedType)
}
// RequiredFieldError occurs when a required field is not set and in the environment variables.
type RequiredFieldError struct {
FieldName string
}
// Error satisfies the error interface for RequiredFieldError.
func (e *RequiredFieldError) Error() string {
return fmt.Sprintf("required field is not set in environment variables: %v", e.FieldName)
}
// InvalidOptionConversionError occurs when an option is invalid for a field.
type InvalidOptionConversionError struct {
FieldName string
Option string
Err error
}
// Error satisfies the error interface for InvalidOptionConversionError.
func (e *InvalidOptionConversionError) Error() string {
return fmt.Sprintf("invalid option %v conversion for field %v: %v", e.Option, e.FieldName, e.Err.Error())
}
// Unwrap allows InvalidOptionConversionError to be used with errors.Is and errors.As.
func (e *InvalidOptionConversionError) Unwrap() error { return e.Err }
// PrefixOptionError occurs when the prefix tag is invalid or not set on a nested struct.
type PrefixOptionError struct {
FieldName any
}
// Error satisfies the error interface for PrefixOptionError.
func (e *PrefixOptionError) Error() string {
return fmt.Sprintf("prefix option is not set for nested struct field: %v", e.FieldName)
}
// ReplacementError occurs when the environment variable being used for replacement is not set.
type ReplacementError struct {
VariableName string
}
// Error satisfies the error interface for ReplacementError.
func (e *ReplacementError) Error() string {
return fmt.Sprintf("environment variable for replacement is not set: %v", e.VariableName)
}
// ParseError occurs when a line from the .env config file has been parsed incorrectly.
type ParseError struct {
Line string
Err error
}
// ErrSyntax indicates that a line is invalid syntax.
var ErrSyntax = errors.New("invalid syntax")
// Error statisfies the error interface for ParseError.
func (e *ParseError) Error() string {
return fmt.Sprintf("parse line: %v: %v", e.Line, e.Err.Error())
}
// FileReadError occurs when an error occurs when scanning the .env file.
type FileReadError struct {
Filepath string
Err error
}
// Error satisfies the error interface for FileReadError.
func (e *FileReadError) Error() string {
return fmt.Sprintf("reading %v: %v", e.Filepath, e.Err.Error())
}
// Unwrap allows FileReadError to be used with errors.Is and errors.As.
func (e *FileReadError) Unwrap() error { return e.Err }
// IncompatibleOptionsError occurs when two options are incompatible with each other, or the usage is invalid.
type IncompatibleOptionsError struct {
FirstOption string
SecondOption string
Reason string
}
// Error satisfies the error interface for FileReadError.
func (e *IncompatibleOptionsError) Error() string {
return fmt.Sprintf(
"incompatible option usage of %v and %v: %v",
e.FirstOption,
e.SecondOption,
e.Reason,
)
}