Issue 13542 - std.file.FileException has GetLastError() as a default argument
Summary: std.file.FileException has GetLastError() as a default argument
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Windows
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-27 20:13 UTC by Walter Bright
Modified: 2024-12-01 16:22 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2014-09-27 20:13:37 UTC
This has problems:

1. GetLastError() is not the same as errno, although D also has errno. So there's confusion and wrong documentation about the arguments.

2. FileException is never called by anyone other than std.file, so the constructor should be marked private.

3. The call to GetLastError() should be moved into the constructor body, in order to reduce bloat (i.e. having code for it generated over and over at the call site).
Comment 1 Vladimir Panteleev 2014-09-28 02:22:18 UTC
Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c2 , we should look into replacing uses of FileException / GetLastError with wenforce.
Comment 2 Walter Bright 2014-09-29 09:54:17 UTC
(In reply to Vladimir Panteleev from comment #1)
> Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c2 , we
> should look into replacing uses of FileException / GetLastError with
> wenforce.

wenforce is currently private and throws an Exception, which would break code that looks for FileException.

While reengineering the interface has its place, this bug report is only about fixing the existing code and the way it works.
Comment 3 Vladimir Panteleev 2014-09-29 10:04:55 UTC
(In reply to Walter Bright from comment #2)
> wenforce is currently private 

No.

> and throws an Exception, 

No. It throws a WindowsException.

> which would break code that looks for FileException.

Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c6 we should introduce OSException make FileException an alias of OS

> While reengineering the interface has its place, this bug report is only
> about fixing the existing code and the way it works.

I suggest fixing the existing code without breaking it. Why do you think I suggested otherwise?
Comment 4 Walter Bright 2014-10-04 09:54:09 UTC
(In reply to Vladimir Panteleev from comment #3)
> (In reply to Walter Bright from comment #2)
> > wenforce is currently private 
> 
> No.
> 
> > and throws an Exception, 
> 
> No. It throws a WindowsException.

Then it has changed recently? stdio.d line 961:

        private static T wenforce(T)(T cond, string str)
        {
            import std.windows.syserror;

            if (cond) return cond;
            throw new Exception(str ~ ": " ~ sysErrorString(GetLastError()));
        }

> 
> > which would break code that looks for FileException.
> 
> Per my comment in https://issues.dlang.org/show_bug.cgi?id=13541#c6 we
> should introduce OSException make FileException an alias of OS
> 
> > While reengineering the interface has its place, this bug report is only
> > about fixing the existing code and the way it works.
> 
> I suggest fixing the existing code without breaking it. Why do you think I
> suggested otherwise?

Because I thought you suggested throwing a different error than FileException. IF that is incorrect, then I was wrong.
Comment 5 Vladimir Panteleev 2014-10-04 14:18:19 UTC
(In reply to Walter Bright from comment #4)
> (In reply to Vladimir Panteleev from comment #3)
> > No. It throws a WindowsException.
> 
> Then it has changed recently? stdio.d line 961:

Oh, that's a completely different wenforce (which I also added a while ago, and forgot about). It should be changed to use the new one, in std.windows.syserror.

> > I suggest fixing the existing code without breaking it. Why do you think I
> > suggested otherwise?
> 
> Because I thought you suggested throwing a different error than
> FileException. IF that is incorrect, then I was wrong.

My suggestion was to make FileException an alias of OSException, so no code will break (unless it compares the class name string from classinfo or something).
Comment 6 Vladimir Panteleev 2014-10-15 15:45:31 UTC
(In reply to Vladimir Panteleev from comment #5)
> My suggestion was to make FileException an alias of OSException, so no code
> will break (unless it compares the class name string from classinfo or
> something).

Elaborated: https://issues.dlang.org/show_bug.cgi?id=13620
Comment 7 dlangBugzillaToGithub 2024-12-01 16:22:30 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10087

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB