Bug 14292 – writing to file opened for reading - error report is nonsense

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-16T15:19:36Z
Last change time
2020-03-21T03:56:34Z
Assigned to
No Owner
Creator
Ivan Kazmenko

Attachments

IDFilenameSummaryContent-TypeSize
1492testwrite.dthe example codetext/plain94

Comments

Comment #0 by gassa — 2015-03-16T15:19:36Z
Created attachment 1492 the example code Say we want to overwrite a file "test.txt". Say we instead have a typo and so open it for reading. After trying to write to the file, a hilarious message appears: ----- std.exception.ErrnoException@<somepath>\std\stdio.d(2113): (No error) ----- The culprit (line 2337 of stdio.d at master currently) is: ----- if (result != writeme.length) errnoEnforce(0); ----- That errnoEnforce(0) produces a nonsense message "...ErrnoException...: (No error)". Which I believe is wrong code regardless of the context. But I don't know which way of reporting the error is right here. Below is the complete example code. The file "test.txt" must be present for it to work. Its contents may be arbitrary. ----- import std.stdio; void main () { auto f = File ("test.txt", "rt"); // file must exist f.writeln ("!"); } -----
Comment #1 by b2.temp — 2017-12-26T09:59:32Z
It gives: std.exception.ErrnoException@/usr/include/dmd/phobos/std/stdio.d(2847): (Bad file descriptor) nowadays