Summary: Bad error messages from attempts to write into
                    read-only File
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from 2010-09-21 17:45:47 PDT ---
This is a wrong Python 2 program, it tries to write on a read mode file:

f = file("test.raw", "r")

Python 2.6.5 gives the run-time error:

Traceback (most recent call last):
  File "...\", line 2, in <module>
IOError: File not open for writing


This is a similar D2 program:

import std.stdio: File;
void main() {
    auto f = File("test.raw", "r");

It generates the run-time error (dmd 2.049):

std.exception.errnoexcept...@...\dmd\src\phobos\std\stdio.d(1060):  (No error)

This error is useless, it doesn't show the line count and file of the problem,
the cause of the problem (the file is read-only) and it doesn't even clearly
show it's a I/O error.


A similarly wrong D2 program:

import std.stdio: File;
void main() {
    double[3] data = [0.5, 1.5, 2.5];
    auto f = File("test.raw", "r");

The error it raises, far still from being a good error message:

std.exception.errnoexcept...@...\dmd\src\phobos\std\stdio.d(508): Wrote 0
instead of 3 objects of type double to file `test.raw' (No error)

A much better error message may be this, that gives the line number and file
name of the module that has produced the error, shows that it's an I/O error,
explains that the bug comes from trying to write in a read-only file, and it
gives the name of the file:

fileioexcept...@test.d(5): attempt to write into read-only file "test.raw".

(Even better, a typestate system is able to spot this bug at compile-time, see
bug 4571 ).

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to