1
mirror of https://github.com/rclone/rclone synced 2024-11-28 06:41:41 +01:00
rclone/vfs/errors.go

50 lines
894 B
Go
Raw Normal View History

// Cross platform errors
package vfs
import (
"fmt"
"os"
)
2017-11-03 12:35:36 +01:00
// Error describes low level errors in a cross platform way.
type Error byte
// NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go
// Low level errors
const (
OK Error = iota
ENOTEMPTY
ESPIPE
EBADF
EROFS
ENOSYS
)
// Errors which have exact counterparts in os
var (
2019-04-15 21:03:33 +02:00
ENOENT = os.ErrNotExist
EEXIST = os.ErrExist
EPERM = os.ErrPermission
EINVAL = os.ErrInvalid
ECLOSED = os.ErrClosed
)
var errorNames = []string{
OK: "Success",
ENOTEMPTY: "Directory not empty",
ESPIPE: "Illegal seek",
EBADF: "Bad file descriptor",
EROFS: "Read only file system",
ENOSYS: "Function not implemented",
}
// Error renders the error as a string
func (e Error) Error() string {
if int(e) >= len(errorNames) {
return fmt.Sprintf("Low level error %d", e)
}
return errorNames[e]
}