{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/9640","labels_url":"https://api.github.com/repos/golang/go/issues/9640/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/9640/comments","events_url":"https://api.github.com/repos/golang/go/issues/9640/events","html_url":"https://github.com/golang/go/issues/9640","id":54834130,"number":9640,"title":"os: File.Truncate reports unhelpful error in Linux.","user":{"login":"Zilog8","id":218071,"avatar_url":"https://avatars.githubusercontent.com/u/218071?v=3","gravatar_id":"","url":"https://api.github.com/users/Zilog8","html_url":"https://github.com/Zilog8","followers_url":"https://api.github.com/users/Zilog8/followers","following_url":"https://api.github.com/users/Zilog8/following{/other_user}","gists_url":"https://api.github.com/users/Zilog8/gists{/gist_id}","starred_url":"https://api.github.com/users/Zilog8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Zilog8/subscriptions","organizations_url":"https://api.github.com/users/Zilog8/orgs","repos_url":"https://api.github.com/users/Zilog8/repos","events_url":"https://api.github.com/users/Zilog8/events{/privacy}","received_events_url":"https://api.github.com/users/Zilog8/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"ianlancetaylor","id":3194333,"avatar_url":"https://avatars.githubusercontent.com/u/3194333?v=3","gravatar_id":"","url":"https://api.github.com/users/ianlancetaylor","html_url":"https://github.com/ianlancetaylor","followers_url":"https://api.github.com/users/ianlancetaylor/followers","following_url":"https://api.github.com/users/ianlancetaylor/following{/other_user}","gists_url":"https://api.github.com/users/ianlancetaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/ianlancetaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianlancetaylor/subscriptions","organizations_url":"https://api.github.com/users/ianlancetaylor/orgs","repos_url":"https://api.github.com/users/ianlancetaylor/repos","events_url":"https://api.github.com/users/ianlancetaylor/events{/privacy}","received_events_url":"https://api.github.com/users/ianlancetaylor/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-01-20T01:46:33Z","updated_at":"2015-01-20T02:43:07Z","closed_at":null,"body":"# What version of Go are you using (go version)?\r\ngo version go1.4 linux/386\r\ngo version go1.4 windows/amd64\r\n# What operating system and processor architecture are you using?\r\nDebian Wheezy, x86\r\nWindows 7, x64\r\n# What did you do?\r\n```go\r\n    filepath := \"/play/p2/test2.txt\"\r\n\tfile, err := os.Open(filepath)\r\n\tif err != nil {\r\n\t\tfmt.Println(\"Error 1\", err)\r\n\t}\r\n\terr = file.Truncate(0)\r\n\tif err != nil {\r\n\t\tfmt.Println(\"Error 2\", err)\r\n\t}\r\n\terr = file.Close()\r\n\tif err != nil {\r\n\t\tfmt.Println(\"Error 3\", err)\r\n\t}\r\n```\r\n# What did you expect to see?\r\n`Error 2 truncate /play/p2/test2.txt: Access is denied`\r\n# What did you see instead?\r\n`Error 2 truncate /play/p2/test2.txt: invalid argument`\r\n\r\nExecuting Truncate(int) rightfully results in an error because os.Open() yields a read-only file handle.\r\nHowever, in windows this error is helpful (the \"expect to see\" above), while in linux it is not helpful (the \"see instead\" above)"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/70596140","html_url":"https://github.com/golang/go/issues/9640#issuecomment-70596140","issue_url":"https://api.github.com/repos/golang/go/issues/9640","id":70596140,"user":{"login":"minux","id":135652,"avatar_url":"https://avatars.githubusercontent.com/u/135652?v=3","gravatar_id":"","url":"https://api.github.com/users/minux","html_url":"https://github.com/minux","followers_url":"https://api.github.com/users/minux/followers","following_url":"https://api.github.com/users/minux/following{/other_user}","gists_url":"https://api.github.com/users/minux/gists{/gist_id}","starred_url":"https://api.github.com/users/minux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minux/subscriptions","organizations_url":"https://api.github.com/users/minux/orgs","repos_url":"https://api.github.com/users/minux/repos","events_url":"https://api.github.com/users/minux/events{/privacy}","received_events_url":"https://api.github.com/users/minux/received_events","type":"User","site_admin":false},"created_at":"2015-01-20T02:43:07Z","updated_at":"2015-01-20T02:43:07Z","body":"That's how Linux reports error when you've provided a read only file\ndescriptor to an operation that requires writing permission. (See man 2\nftruncate)\n\nActually, if you look at the man page, EBADF / EINVAL is only used for the\n\"fd is not open for writing error\", so the error is not ambiguous.\n\nIt's not feasible for the os package to try to provide better error message\nthan what the underlying syscall provides in every case.\n\nPS: when debugging this kind of issue, I suggest using strace."}}