[Issue 14292] New: writing to file opened for reading - incorrect error report

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Mar 16 08:19:36 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14292

          Issue ID: 14292
           Summary: writing to file opened for reading - incorrect error
                    report
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: gassa at 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
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 ("!");
}
-----

--


More information about the Digitalmars-d-bugs mailing list