u-root icon indicating copy to clipboard operation
u-root copied to clipboard

uio package lazy reader reports a close error even when it does not report an open error

Open rminnich opened this issue 6 years ago • 3 comments

The uio package lazy reader function can get an open error, should the program hand it a pathname of a file that can't be opened. It won't report it because it's a lazy open; it will be seen by the app as a read error, since the open occurs on first read. When the app tries to close the file, it can get a close error -- because the file in this case is not open. But the app did not get an open error. Getting a close error on a readonly file, when the open did not fail, is confusing.

The uio package lazy read function should not return close errors; or, at least, it could track when an open failed and in that case it can ignore the close error.

rminnich avatar Jun 26 '19 01:06 rminnich

If the open() returns an error, lr.r should be nil.

What you're describing is only ever possible if you give the lazy reader an open function that returns both a non-nil object and an error at the same time.

func open() {
  return foostruct{}, fmt.Errorf("...")
}

Where have you seen such an open function

hugelgupf avatar Jun 26 '19 01:06 hugelgupf

seen in the wild in our cpio command. It's in my closed pr.

rminnich avatar Jun 27 '19 15:06 rminnich

Do you have a log or anything? Reading the code, I cannot imagine this is possible.

hugelgupf avatar Jun 27 '19 15:06 hugelgupf