Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

but how would you do that otherwise? Genuinely curious cause I looked up both the go docs and source (disclaimer: not a go dev), and there doesn't seem a way to handle that specific kind of error through stuff like `errors.Is`, at least from what I can tell, at least in the os and fs packages


He can do a test using `errors.Is(err, syscall.ENOTDIR)`

  func rootInfo(root, p string) (has bool, isDir bool, err error) {
   p = path.Clean(p)
   info, err := os.Stat(root + "/" + p)
   if info != nil {
    has, isDir = true, info.IsDir()
    return
   }
   if errors.Is(err, os.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) {
    err = nil
   }
   return
  }


From what the comments are saying I think you downcast with `errors.As` and then work on the underlying error type. But I don't know for sure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: