-
Notifications
You must be signed in to change notification settings - Fork 99
/
errors.go
80 lines (65 loc) · 1.86 KB
/
errors.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
package ftpserver
import (
"errors"
"fmt"
)
var (
// ErrStorageExceeded defines the error mapped to the FTP 552 reply code.
// As for RFC 959 this error is checked for STOR, APPE
ErrStorageExceeded = errors.New("storage limit exceeded")
// ErrFileNameNotAllowed defines the error mapped to the FTP 553 reply code.
// As for RFC 959 this error is checked for STOR, APPE, RNTO
ErrFileNameNotAllowed = errors.New("filename not allowed")
)
func getErrorCode(err error, defaultCode int) int {
switch {
case errors.Is(err, ErrStorageExceeded):
return StatusActionAborted
case errors.Is(err, ErrFileNameNotAllowed):
return StatusActionNotTakenNoFile
default:
return defaultCode
}
}
// DriverError is a wrapper is for any error that occur while contacting the drivers
type DriverError struct {
str string
err error
}
func newDriverError(str string, err error) DriverError {
return DriverError{str: str, err: err}
}
func (e DriverError) Error() string {
return fmt.Sprintf("driver error: %s: %v", e.str, e.err)
}
func (e DriverError) Unwrap() error {
return e.err
}
// NetworkError is a wrapper for any error that occur while contacting the network
type NetworkError struct {
str string
err error
}
func newNetworkError(str string, err error) NetworkError {
return NetworkError{str: str, err: err}
}
func (e NetworkError) Error() string {
return fmt.Sprintf("network error: %s: %v", e.str, e.err)
}
func (e NetworkError) Unwrap() error {
return e.err
}
// FileAccessError is a wrapper for any error that occur while accessing the file system
type FileAccessError struct {
str string
err error
}
func newFileAccessError(str string, err error) FileAccessError {
return FileAccessError{str: str, err: err}
}
func (e FileAccessError) Error() string {
return fmt.Sprintf("file access error: %s: %v", e.str, e.err)
}
func (e FileAccessError) Unwrap() error {
return e.err
}