www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - isDir won't throw FileException with dirEntries

reply Nick Treleaven <nospam example.com> writes:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,
With the attached source file on Windows, dmd 2.054, I'm not getting an 
exception when the path doesn't exist. If I uncomment the foreach line, 
the exception is thrown. Should I file this in bugzilla?

Thanks
Aug 30 2011
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, August 30, 2011 10:39 Nick Treleaven wrote:
 Hi,
 With the attached source file on Windows, dmd 2.054, I'm not getting an
 exception when the path doesn't exist. If I uncomment the foreach line,
 the exception is thrown. Should I file this in bugzilla?

So, what exactly is the problem? Is the issue that isDir isn't throwing or that dirEntries isn't throwing? isDir should definitely throw if the path doesn't exist, but I'm not sure that dirEntries will. It'll throw once you try and iterate over it, but dirEntries returns a range of DirEntrys which is lazy. So, there's a decent chance that it doesn't actually do anything with the path that you gave it until you try and iterate it. I'd have to look at the implementation though to see whether that's the case. Regardless, if the issue is that dirEntries doesn't throw, and that you only get an exception when you actually iterate over the return value from dirEntries, then I don't think that that's really a bug. Assuming that it doesn't currently throw on a bad path until you iterate, it may or may not be desirable to make it so that dirEntries does an additional check to verify that the path is valid, but since it would throw once you started iterating, I don't think that it's really a problem - especially if checking whether the path is valid before iteration means making an additional system call. - Jonathan M Davis
Aug 30 2011
parent reply Nick Treleaven <nospam example.com> writes:
On 30/08/2011 18:54, Jonathan M Davis wrote:
 On Tuesday, August 30, 2011 10:39 Nick Treleaven wrote:
 Hi,
 With the attached source file on Windows, dmd 2.054, I'm not getting an
 exception when the path doesn't exist. If I uncomment the foreach line,
 the exception is thrown. Should I file this in bugzilla?

So, what exactly is the problem? Is the issue that isDir isn't throwing or that dirEntries isn't throwing? isDir should definitely throw if the path doesn't exist, but I'm not sure that dirEntries will.

The problem is that isDir doesn't throw - the documentation says: "Throws: FileException if the given file does not exist. " If I remove the foreach/dirEntries then isDir does throw.
Aug 30 2011
next sibling parent reply Nick Treleaven <nospam example.com> writes:
On 30/08/2011 19:02, Nick Treleaven wrote:
 On 30/08/2011 18:54, Jonathan M Davis wrote:
 On Tuesday, August 30, 2011 10:39 Nick Treleaven wrote:
 Hi,
 With the attached source file on Windows, dmd 2.054, I'm not getting an
 exception when the path doesn't exist. If I uncomment the foreach line,
 the exception is thrown. Should I file this in bugzilla?

So, what exactly is the problem? Is the issue that isDir isn't throwing or that dirEntries isn't throwing? isDir should definitely throw if the path doesn't exist, but I'm not sure that dirEntries will.

The problem is that isDir doesn't throw - the documentation says: "Throws: FileException if the given file does not exist. " If I remove the foreach/dirEntries then isDir does throw.

BTW, I meant to say 'comment the foreach line' in my first post, sorry for the confusion...
Aug 30 2011
next sibling parent Nick Treleaven <nospam example.com> writes:
On 30/08/2011 19:17, Jonathan M Davis wrote:
 On Tuesday, August 30, 2011 11:04 Nick Treleaven wrote:
 On 30/08/2011 19:02, Nick Treleaven wrote:
 On 30/08/2011 18:54, Jonathan M Davis wrote:
 On Tuesday, August 30, 2011 10:39 Nick Treleaven wrote:
 Hi,
 With the attached source file on Windows, dmd 2.054, I'm not getting an
 exception when the path doesn't exist. If I uncomment the foreach line,
 the exception is thrown. Should I file this in bugzilla?

So, what exactly is the problem? Is the issue that isDir isn't throwing or that dirEntries isn't throwing? isDir should definitely throw if the path doesn't exist, but I'm not sure that dirEntries will.

The problem is that isDir doesn't throw - the documentation says: "Throws: FileException if the given file does not exist." If I remove the foreach/dirEntries then isDir does throw.

BTW, I meant to say 'comment the foreach line' in my first post, sorry for the confusion...

So, you're saying that import std.file; void main(string[] args) { auto path = args[1]; if (!path.isDir()) { } //foreach (DirEntry f; dirEntries(path, SpanMode.depth)) { } } fails to throw on your system, whereas import std.file; void main(string[] args) { auto path = args[1]; if (!path.isDir()) { } foreach (DirEntry f; dirEntries(path, SpanMode.depth)) { } } _does_ throw? If so, that's a compiler bug. The foreach should have _zero_ effect on the statements before it - save for stuff like scope statements.

Actually the opposite - it works fine without the foreach. Anyway it seems fairly clear now that it is a compiler bug, I'll file it. Thanks for the info.
Aug 30 2011
prev sibling parent Nick Treleaven <nospam example.com> writes:
On 30/08/2011 19:25, Andrej Mitrovic wrote:
 This is probably relevant to:
 http://d.puremagic.com/issues/show_bug.cgi?id=6329
 http://d.puremagic.com/issues/show_bug.cgi?id=6308

 But that is all still broken from what I can tell. It used to work
 fine in 2.053.

Looks like it is related. Another duplicate of bug 6308 looks like my example but reduced more: http://d.puremagic.com/issues/show_bug.cgi?id=6363 That one is now marked resolved, so hopefully my problem is fixed. It seems any exception thrown just before using dirEntries was not firing with dmd 2.054 32bit on Windows (XP). E.g. void main(string[] args) { auto path = args[1]; // RangeError with no user args //dirEntries("", SpanMode.depth); // hides exception } Thanks
Aug 31 2011
prev sibling next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Tuesday, August 30, 2011 11:04 Nick Treleaven wrote:
 On 30/08/2011 19:02, Nick Treleaven wrote:
 On 30/08/2011 18:54, Jonathan M Davis wrote:
 On Tuesday, August 30, 2011 10:39 Nick Treleaven wrote:
 Hi,
 With the attached source file on Windows, dmd 2.054, I'm not getting an
 exception when the path doesn't exist. If I uncomment the foreach line,
 the exception is thrown. Should I file this in bugzilla?

So, what exactly is the problem? Is the issue that isDir isn't throwing or that dirEntries isn't throwing? isDir should definitely throw if the path doesn't exist, but I'm not sure that dirEntries will.

The problem is that isDir doesn't throw - the documentation says: "Throws: FileException if the given file does not exist. " If I remove the foreach/dirEntries then isDir does throw.

BTW, I meant to say 'comment the foreach line' in my first post, sorry for the confusion...

So, you're saying that import std.file; void main(string[] args) { auto path = args[1]; if (!path.isDir()) { } //foreach (DirEntry f; dirEntries(path, SpanMode.depth)) { } } fails to throw on your system, whereas import std.file; void main(string[] args) { auto path = args[1]; if (!path.isDir()) { } foreach (DirEntry f; dirEntries(path, SpanMode.depth)) { } } _does_ throw? If so, that's a compiler bug. The foreach should have _zero_ effect on the statements before it - save for stuff like scope statements. - Jonathan M Davis
Aug 30 2011
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
This is probably relevant to:
http://d.puremagic.com/issues/show_bug.cgi?id=6329
http://d.puremagic.com/issues/show_bug.cgi?id=6308

But that is all still broken from what I can tell. It used to work
fine in 2.053.
Aug 30 2011