github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/vfs/errors.go (about) 1 // Cross platform errors 2 3 package vfs 4 5 import ( 6 "fmt" 7 "os" 8 ) 9 10 // Error describes low level errors in a cross platform way. 11 type Error byte 12 13 // NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go 14 15 // Low level errors 16 const ( 17 OK Error = iota 18 ENOTEMPTY 19 ESPIPE 20 EBADF 21 EROFS 22 ENOSYS 23 ) 24 25 // Errors which have exact counterparts in os 26 var ( 27 ENOENT = os.ErrNotExist 28 EEXIST = os.ErrExist 29 EPERM = os.ErrPermission 30 EINVAL = os.ErrInvalid 31 ECLOSED = os.ErrClosed 32 ) 33 34 var errorNames = []string{ 35 OK: "Success", 36 ENOTEMPTY: "Directory not empty", 37 ESPIPE: "Illegal seek", 38 EBADF: "Bad file descriptor", 39 EROFS: "Read only file system", 40 ENOSYS: "Function not implemented", 41 } 42 43 // Error renders the error as a string 44 func (e Error) Error() string { 45 if int(e) >= len(errorNames) { 46 return fmt.Sprintf("Low level error %d", e) 47 } 48 return errorNames[e] 49 }