-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
55 lines (45 loc) · 1.18 KB
/
Copy patherrors.go
File metadata and controls
55 lines (45 loc) · 1.18 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
package dotenvgo
import (
"fmt"
"strings"
)
// RequiredError is returned when a required environment variable is not set.
type RequiredError struct {
Key string
}
func (e *RequiredError) Error() string {
return fmt.Sprintf("dotenvgo: required environment variable %q is not set", e.Key)
}
// ParseError is returned when an environment variable cannot be parsed.
type ParseError struct {
Key string
Value string
Err error
}
func (e *ParseError) Error() string {
return fmt.Sprintf("dotenvgo: cannot parse %q=%q: %v", e.Key, e.Value, e.Err)
}
// Unwrap returns the underlying error.
func (e *ParseError) Unwrap() error {
return e.Err
}
// MultiError contains multiple errors from struct loading.
type MultiError struct {
Errors []error
}
func (e *MultiError) Error() string {
if len(e.Errors) == 1 {
return e.Errors[0].Error()
}
// Build detailed error message listing all errors
var msg strings.Builder
fmt.Fprintf(&msg, "dotenvgo: %d errors occurred:\n", len(e.Errors))
for i, err := range e.Errors {
fmt.Fprintf(&msg, " [%d] %s\n", i+1, err.Error())
}
return msg.String()
}
// Unwrap returns the list of errors.
func (e *MultiError) Unwrap() []error {
return e.Errors
}