-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: File.Truncate reports unhelpful error in Linux. #9640
Comments
Assigning to @ianlancetaylor to decide if this is something we should care about. Where does this end? There are surely tons of different error messages between operating systems. |
I agree it's not exactly a critical issue :-). However, precise and accurate error messages are very useful. I just spent a few hours trying to figure out why my code wasn't working (my project involves joining various filesystems through an abstraction layer, which is then shared over NFS, so it could've been a couple of different things going wrong), until I decided to try various snippets of it on a windows machine. Once I had the windows error message it was just a few moments before I knew exactly what was wrong and why. My issue isn't that the messages are different. It's that the message in Linux is so un-useful. |
That's how Linux reports error when you've provided a read only file Actually, if you look at the man page, EBADF / EINVAL is only used for the It's not feasible for the os package to try to provide better error message PS: when debugging this kind of issue, I suggest using strace. |
Hmm.. the documentation that I read showed: EINVAL
The argument length is negative or larger than the maximum file size. However, further down on the page it does say, which I hadn't noticed earlier: EBADF or EINVAL
fd is not open for writing.
EINVAL
fd does not reference a regular file. Well, if Linux itself is what provides the ambiguous error, I guess there's not much to be done. Adding extra logic just for this is probably not worth it. |
The first part of the man page is for truncate(2), and the 2nd part is Close as nothing to do. |
What version of Go are you using (go version)?
go version go1.4 linux/386
go version go1.4 windows/amd64
What operating system and processor architecture are you using?
Debian Wheezy, x86
Windows 7, x64
What did you do?
What did you expect to see?
Error 2 truncate /play/p2/test2.txt: Access is denied
What did you see instead?
Error 2 truncate /play/p2/test2.txt: invalid argument
Executing Truncate(int) rightfully results in an error because os.Open() yields a read-only file handle.
However, in windows this error is helpful (the "expect to see" above), while in linux it is not helpful (the "see instead" above)
The text was updated successfully, but these errors were encountered: