www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14292] New: writing to file opened for reading - incorrect


          Issue ID: 14292
           Summary: writing to file opened for reading - incorrect error
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: gassa mail.ru

Created attachment 1492
  --> https://issues.dlang.org/attachment.cgi?id=1492&action=edit
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
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 ("!");

Mar 16 2015