errors.go 894 B

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