errors.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package hackpadfs
  2. import (
  3. "io/fs"
  4. "syscall"
  5. )
  6. // Errors commonly returned by file systems. Mirror their equivalents in the syscall and io/fs packages.
  7. var (
  8. ErrInvalid = syscall.EINVAL // TODO update to fs.ErrInvalid, once errors.Is supports it
  9. ErrPermission = fs.ErrPermission
  10. ErrExist = fs.ErrExist
  11. ErrNotExist = fs.ErrNotExist
  12. ErrClosed = fs.ErrClosed
  13. ErrIsDir = syscall.EISDIR
  14. ErrNotDir = syscall.ENOTDIR
  15. ErrNotEmpty = syscall.ENOTEMPTY
  16. ErrNotImplemented = syscall.ENOSYS
  17. SkipDir = fs.SkipDir
  18. )
  19. // PathError records a file system or file operation error and the path that caused it. Mirrors io/fs.PathError
  20. type PathError = fs.PathError
  21. // LinkError records a file system rename error and the paths that caused it. Mirrors os.LinkError
  22. //
  23. // NOTE: Is not identical to os.LinkError to avoid importing "os". Still resolves errors.Is() calls correctly.
  24. type LinkError struct {
  25. Err error
  26. Op string
  27. Old string
  28. New string
  29. }
  30. func (e *LinkError) Error() string {
  31. return e.Op + " " + e.Old + " " + e.New + ": " + e.Err.Error()
  32. }
  33. // Unwrap supports errors.Unwrap().
  34. func (e *LinkError) Unwrap() error {
  35. return e.Err
  36. }